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:

  1. Each player picks one card from the deck. The chosen card becomes the player's hand.
  2. 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

Copy
8 6

Sample Output 1

Copy
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

Copy
1 1

Sample Output 2

Copy
Draw

Since their cards have the same number, the game will be drawn.


Sample Input 3

Copy
13 1

Sample Output 3

Copy
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,jN).
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,jM).

Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.

Constraints

  • 1≦MN≦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

Copy
3 2
#.#
.#.
#.#
#.
.#

Sample Output 1

Copy
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

Copy
4 1
....
....
....
....
#

Sample Output 2

Copy
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≤iM), and double edges are two edges where (ai,bi)=(aj,bj) or (ai,bi)=(bj,aj)(1≤i<jM).
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≦MN(N−1)⁄2
  • 1≦ai<biN
  • 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

Copy
3 3
1 2
1 3
2 3

Sample Output 1

Copy
2

The given graph is shown in the following figure:

The following two paths satisfy the condition:


Sample Input 2

Copy
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

Sample Output 2

Copy
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
  • aibiciMa 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

Copy
3 1 1
1 2 1
2 1 2
3 3 10

Sample Output 1

Copy
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

Copy
1 1 10
10 10 10

Sample Output 2

Copy
-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题的更多相关文章

  1. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  2. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  3. AtCoder Beginner Contest 069 ABCD题

    题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...

  4. AtCoder Beginner Contest 070 ABCD题

    题目链接:http://abc070.contest.atcoder.jp/assignments A - Palindromic Number Time limit : 2sec / Memory ...

  5. AtCoder Beginner Contest 057 ABCD题

    A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...

  6. AtCoder Beginner Contest 051 ABCD题

    A - Haiku Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement As a New Yea ...

  7. AtCoder Beginner Contest 052 ABCD题

    A - Two Rectangles Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement The ...

  8. AtCoder Beginner Contest 058 ABCD题

    A - ι⊥l Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Three poles st ...

  9. AtCoder Beginner Contest 050 ABC题

    A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...

随机推荐

  1. 使用dbms_stats.gather_table_stats调整表的统计信息

    创建实验表,插入10万行数据 SQL> create table test (id number,name varchar2(10)); Table created. SQL> decla ...

  2. 关于MySQL的information_schema库简单介绍及实际应用

    本文简介 写本文主要是围绕下面几点进行的. 1.information_schema数据库到底是做什么用的? 2.执行alter table 表名 modify column 字段名 类型 这个sql ...

  3. HDU4686 Arc of Dream —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-4686 Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memo ...

  4. Appium基础——需要知道的

      Appium使用平台厂商提供的自动化框架: 1.ios 苹果的UIAutomation 2.android google的UIAutomator Appium底层使用厂商提供的自动化框架,就不需要 ...

  5. Nginx配置故障转移

    当上游服务器(真实访问服务器),一旦出现故障或者是没有及时相应的话,应该直接轮训到下一台服务器,保证服务器的高可用. 如果上游服务器的某一台宕机了,直接轮训到下一个~ 8080 8081 8082 关 ...

  6. webrtc 学习资源1

    1,http://www.webrtc.org/  webrtc官网,神马编译,神马下载,这里的解决方案才是最权威的. --------------------------------- 2,http ...

  7. RTMP协议的理解

    RTMP协议:real time message protocol 工作原理: 先采集摄像头视频和麦克风音频信息,再进行音视频的编码(mpeg),通过FMLE(Flash Media Live Enc ...

  8. ACM应该学什么(知乎学长)

    网络上流传的答案有很多,估计提问者也曾经去网上搜过.所以根据自己微薄的经验提点看法. 我ACM初期是训练编码能力,以水题为主(就是没有任何算法,自己靠动脑筋能够实现的),这种题目特点是麻烦,但是不难, ...

  9. keras中的Flatten和Reshape

    最近在看SSD源码的时候,就一直不理解,在模型构建的时候如果使用Flatten或者是Merge层,那么整个数据的shape就发生了变化,那么还可以对应起来么(可能你不知道我在说什么)?后来不知怎么的, ...

  10. HihoCoder 1590 : 紧张的会议室(区间最大+离散化)

    时间限制:20000ms 单点时限:2000ms 内存限制:256MB 描述 小Hi的公司最近员工增长迅速,同时大大小小的会议也越来越多:导致公司内的M间会议室非常紧张. 现在小Hi知道公司目前有N个 ...