AtCoder Beginner Contest 054 ABCD题
A - One Card Poker
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
Alice and Bob are playing One Card Poker.
One Card Poker is a two-player game using playing cards.
Each card in this game shows an integer between 1
and 13
, inclusive.
The strength of a card is determined by the number written on it, as follows:
Weak 2
< 3
< 4
< 5
< 6
< 7
< 8
< 9
< 10
< 11
< 12
< 13
< 1
Strong
One Card Poker is played as follows:
- Each player picks one card from the deck. The chosen card becomes the player's hand.
- The players reveal their hands to each other. The player with the stronger card wins the game.
If their cards are equally strong, the game is drawn.
You are watching Alice and Bob playing the game, and can see their hands.
The number written on Alice's card is A, and the number written on Bob's card is B.
Write a program to determine the outcome of the game.
Constraints
- 1≦A≦13
- 1≦B≦13
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print Alice
if Alice will win. Print Bob
if Bob will win. Print Draw
if the game will be drawn.
Sample Input 1
8 6
Sample Output 1
Alice
8
is written on Alice's card, and 6
is written on Bob's card. Alice has the stronger card, and thus the output should be Alice
.
Sample Input 2
1 1
Sample Output 2
Draw
Since their cards have the same number, the game will be drawn.
Sample Input 3
13 1
Sample Output 3
Bob
题意:比较大小
解法:就1需要变换成为14之外,其他不变
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n,m;
cin>>n>>m;
if(n==)
{
n=;
}
if(m==)
{
m=;
}
if(n==m)
{
cout<<"Draw";
}
else if(n<m)
{
cout<<"Bob";
}
else
{
cout<<"Alice";
}
return ;
}
B - Template Matching
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: .
corresponds to a white pixel, and #
corresponds to a black pixel.
The image A is given as N strings A1,…,AN.
The j-th character in the string Ai corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B1,…,BM.
The j-th character in the string Bi corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
- 1≦M≦N≦50
- Ai is a string of length N consisting of
#
and.
. - Bi is a string of length M consisting of
#
and.
.
Input
The input is given from Standard Input in the following format:
N M
A1
A2
:
AN
B1
B2
:
BM
Output
Print Yes
if the template image B is contained in the image A. Print No
otherwise.
Sample Input 1
3 2
#.#
.#.
#.#
#.
.#
Sample Output 1
Yes
The template image B is identical to the upper-left 2×2 subimage and the lower-right 2×2 subimage of A. Thus, the output should be Yes
.
Sample Input 2
4 1
....
....
....
....
#
Sample Output 2
No
The template image B, composed of a black pixel, is not contained in the image A composed of white pixels.
题意:问二图是不是一图的子图
解法:数据量不大,暴力
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char a[][],b[][];
int n,m;
int main()
{
cin>>n>>m;
for(int i=;i<n;i++)
{
scanf("%s",a[i]);
}
for(int i=;i<m;i++)
{
scanf("%s",b[i]);
}
int flag=;
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{ if(a[i][j]==b[][])
{
flag=;
for(int x=;x<m;x++)
{
for(int y=;y<m;y++)
{
if(a[i+x][j+y]!=b[x][y])
{
flag=;
break;
}
}
}
}
if(flag==)
{
cout<<"Yes";
return ;
}
}
}
cout<<"No";
return ;
}
C - One-stroke Path
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges.
Here, a self-loop is an edge where ai=bi(1≤i≤M), and double edges are two edges where (ai,bi)=(aj,bj) or (ai,bi)=(bj,aj)(1≤i<j≤M).
How many different paths start from vertex 1 and visit all the vertices exactly once?
Here, the endpoints of a path are considered visited.
For example, let us assume that the following undirected graph shown in Figure 1 is given.
Figure 1: an example of an undirected graph
The following path shown in Figure 2 satisfies the condition.
Figure 2: an example of a path that satisfies the condition
However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices.
Figure 3: an example of a path that does not satisfy the condition
Neither the following path shown in Figure 4, because it does not start from vertex 1.
Figure 4: another example of a path that does not satisfy the condition
Constraints
- 2≦N≦8
- 0≦M≦N(N−1)⁄2
- 1≦ai<bi≦N
- The given graph contains neither self-loops nor double edges.
Input
The input is given from Standard Input in the following format:
N M
a1 b1
a2 b2
:
aM bM
Output
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once.
Sample Input 1
3 3
1 2
1 3
2 3
Sample Output 1
2
The given graph is shown in the following figure:
The following two paths satisfy the condition:
Sample Input 2
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
Sample Output 2
1
This test case is the same as the one described in the problem statement.
题意:求从1开始到每个点的路径有多少种
解法:数据量不大,可以是由1开始的全排列,看是否符合
或者从1开始搜索,能够访问所有点就加一
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
vector<int>m[maxn];
int n,p;
int sum;
int vis[maxn];
void dfs(int cot,int num)
{
if(num==n)
{
sum++;
return;
}
for(int i=;i<m[cot].size();i++)
{
if(vis[m[cot][i]]==)
{
vis[m[cot][i]]=;
dfs(m[cot][i],num+);
vis[m[cot][i]]=;
}
}
}
int main()
{
cin>>n>>p;
for(int i=;i<=p;i++)
{
int v,u;
cin>>v>>u;
m[v].push_back(u);
m[u].push_back(v);
}
sum=;
vis[]=;
dfs(,);
cout<<sum<<endl;
return ;
}
D - Mixing Experiment
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
Dolphin is planning to generate a small amount of a certain chemical substance C.
In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of Ma:Mb.
He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy.
The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock.
The package of chemical i contains ai grams of the substance A and bi grams of the substance B, and is sold for ci yen (the currency of Japan).
Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C.
Find the minimum amount of money required to generate the substance C.
If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact.
Constraints
- 1≦N≦40
- 1≦ai,bi≦10
- 1≦ci≦100
- 1≦Ma,Mb≦10
- gcd(Ma,Mb)=1
- ai, bi, ci, Ma and Mb are integers.
Input
The input is given from Standard Input in the following format:
N Ma Mb
a1 b1 c1
a2 b2 c2
:
aN bN cN
Output
Print the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C, print -1
instead.
Sample Input 1
3 1 1
1 2 1
2 1 2
3 3 10
Sample Output 1
3
The amount of money spent will be minimized by purchasing the packages of chemicals 1 and 2.
In this case, the mixture of the purchased chemicals will contain 3 grams of the substance A and 3 grams of the substance B, which are in the desired ratio: 3:3=1:1.
The total price of these packages is 3 yen.
Sample Input 2
1 1 10
10 10 10
Sample Output 2
-1
The ratio 1:10 of the two substances A and B cannot be satisfied by purchasing any combination of the packages. Thus, the output should be -1
.
题意:求能够配出Ma:Mb的比例药剂最小花费
解法:dp[i][j][z]中i表示已经考虑了第i种配方,j表示已经配了a的容量,z表示已经配了b的容量,先初始化他们的最大值,dp[0][0][0]=0
dp[i+1][j][z]=min(dp[i][j][z],dp[i+1][j][z]) 没有加i配方进去
dp[i+1][j+a[i]][z+b[i]]=min(dp[i+1][j+a[i]][z+b[i]],dp[i][j][z]+c[i]) 加了配方i进去
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int a[maxn],b[maxn],c[maxn];
int ans,n,k;
int x,y;
int Ma,Mb;
int inf=;
int dp[][][];
int main()
{
cin>>n>>Ma>>Mb;
for(int i=;i<n;i++)
{
cin>>a[i]>>b[i]>>c[i];
}
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
for(int z=;z<=;z++)
{
dp[i][j][z]=inf;
}
}
}
dp[][][]=;
for(int i=;i<n;i++)
{
for(int j=;j<=;j++)
{
for(int z=;z<=;z++)
{
if(dp[i][j][z]==inf) continue;
dp[i+][j][z]=min(dp[i][j][z],dp[i+][j][z]);
dp[i+][j+a[i]][z+b[i]]=min(dp[i+][j+a[i]][z+b[i]],dp[i][j][z]+c[i]);
}
}
}
int Minx=inf;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(i*Mb==j*Ma)
{
Minx=min(Minx,dp[n][i][j]);
}
}
}
if(Minx==inf)
{
cout<<"-1";
}
else
{
cout<<Minx;
}
return ;
}
AtCoder Beginner Contest 054 ABCD题的更多相关文章
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 069 ABCD题
题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...
- AtCoder Beginner Contest 070 ABCD题
题目链接:http://abc070.contest.atcoder.jp/assignments A - Palindromic Number Time limit : 2sec / Memory ...
- AtCoder Beginner Contest 057 ABCD题
A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...
- AtCoder Beginner Contest 051 ABCD题
A - Haiku Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement As a New Yea ...
- AtCoder Beginner Contest 052 ABCD题
A - Two Rectangles Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement The ...
- AtCoder Beginner Contest 058 ABCD题
A - ι⊥l Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Three poles st ...
- AtCoder Beginner Contest 050 ABC题
A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...
随机推荐
- charles刷分微信跳一跳小程序对https的理解
以前以为只要安装了https 客户端与服务端的数据会被加密就安全了 事实上 只要任意一款抓包工具 并伪造证书 就可以解密这个被所谓https加密的数据 如 可以下载charles的根证书 作为伪 ...
- 官方文档Core Technologies - Part 1
首先介绍系列文章内容及Spring Framework官方文档情况. 在这一系列学习中,我阅读的主要资源是5.1.2 Reference Doc.,以及论坛大神的讲解blog.另外,Spring官方也 ...
- linux应用之php开发环境lamp搭建(centos)
搭建linux+apache+mysql+php环境 1.安装apache: yum install httpd httpd-devel 启动apache: /etc/init.d/httpd ...
- Vue父子组件间的通信
父组件通过 props 向下传递数据给子组件,子组件通过 events 向上给父组件发送消息. 父组件: <div> <div style="background:#344 ...
- BZOJ_3545_[ONTAK2010]Peaks_主席树+倍增+kruscal重构树+dfs序
BZOJ_3545_[ONTAK2010]Peaks_主席树+倍增+kruscal重构树 Description 在Bytemountains有N座山峰,每座山峰有他的高度h_i.有些山峰之间有双向道 ...
- [SHOI 2017] 寿司餐厅
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4873 [算法] 注意到题目中的限制条件可表述为 : 若选择区间[L , R] , 则 ...
- eclipse代码编辑器中按alt+/提示No Default Proposals 的解决方法
window-> Preferences-> Java-> Editor-> Content Assist-> Advanced 上面的选项卡Select the pro ...
- vscode实现列编辑
ctrl + shift + 左键选择要编辑的列 好用,再也不用使用\n替换了
- 创建Sitemap文件供搜索引擎使用
以下内容转载自 http://www.cnblogs.com/webtrados/archive/2009/12/29/1635305.html 如何创建Sitemap文件 Sitemap的格式有XM ...
- Java字节码指令收集大全
Java字节码指令大全 常量入栈指令 指令码 操作码(助记符) 操作数 描述(栈指操作数栈) 0x01 aconst_null null值入栈. 0x02 iconst_m1 -1(int)值入栈. ...