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 ...
随机推荐
- 模拟等待事件:db file sequential read
相关知识: db file sequential read 单块读 optimizer_index_cost_adj 这个初始化参数代表一个百分比,取值范围在1到10000之间.该参数表示索引扫描和 ...
- PYTHON 爬虫笔记二:Urllib库基本使用
知识点一:urllib的详解及基本使用方法 一.基本介绍 urllib是python的一个获取url(Uniform Resource Locators,统一资源定址器)了,我们可以利用它来抓取远程的 ...
- Android高手应该精通哪些内容
很多Android开发者已经度过了初级.中级,如何成为一个Android高手呢? Android123就各个级别的程序员应该掌握哪些内容作为下面分类. 一.初级 1. 拥有娴熟的Java基础,理解设计 ...
- 从Inception v1,v2,v3,v4,RexNeXt到Xception再到MobileNets,ShuffleNet,MobileNetV2
from:https://blog.csdn.net/qq_14845119/article/details/73648100 Inception v1的网络,主要提出了Inceptionmodule ...
- POJ1236 Network of Schools (强连通分量,注意边界)
A number of schools are connected to a computer network. Agreements have been developed among those ...
- VirtualBox下安装ubuntu图文教程以及软件安装
一. 下载安装VirtualBox 官网下载VirtualBox,目前版本:VirtualBox 5.1.8 for Windows hosts x86/amd64 下载好了安装VirtualBox, ...
- POJ2184(01背包变形)
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11092 Accepted: 4404 D ...
- UVA562(01背包均分问题)
Dividing coins Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descriptio ...
- 数论 N是完全平方数 充分必要条件 N有奇数个约数
N是完全平方数 <----> N有奇数个约数 设:N = n*n 充分性: 1.N=1时,N的约数为1,为奇数 2.N>1时,1.....n......N,其中 1, n, N为N的 ...
- ajax展示新页面同时传递参数
HTML页面部分代码: <div id="course" hidden></div> HTML页面中ajax代码: var selectType=$(&qu ...