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 ...
随机推荐
- Linux系统上安装字体
最近项目中需要控制字体类型,然后就上网查了一下在linux系统上安装字体,在window上和linux上,字体要求一样,都是ttf格式,下面这是window上的字体截图 在linux系统中的/usr/ ...
- LightOJ - 1104 Birthday Paradox —— 概率
题目链接:https://vjudge.net/problem/LightOJ-1104 1104 - Birthday Paradox PDF (English) Statistics For ...
- ansible-playbook初始化服务器
hosts ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ [test] 0.0.0.0 ansible_ssh_us ...
- ffmpeg full help
Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile ...
- SqlServer--学习触发器
触发器是一种特殊的存储过程,一种不能被显式执行,而必须依附于一个事件的过程 主要作用:自动化操作;减少手动操作以及出错的几率. 触发器分类:DML(Data Manipulation Language ...
- Python: PS 滤镜--旋涡特效
本文用Python 实现 PS 滤镜的旋涡特效,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/42215 ...
- luogu 3389 【模板】高斯消元
大概就是对每一行先找到最大的减小误差,然后代入消元 #include<iostream> #include<cstdio> #include<cstring> #i ...
- python 基础之第十一天(面向对象)
#############面向对象##################### 类: In [1]: class MyClass(object): ##用class定义一个类 ...: def psta ...
- 基于WinDbg的内存泄漏分析
在前面C++中基于Crt的内存泄漏检测一文中提到的方法已经可以解决我们的大部分内存泄露问题了,但是该方法是有前提的,那就是一定要有源代码,而且还只能是Debug版本调试模式下.实际上很多时候我们的程序 ...
- HDU3065(AC自动机入门题)
病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...