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. codeforces C. Team 解题报告

    题目链接:http://codeforces.com/problemset/problem/401/C 题目意思:给出0和1的数目(分别为n和m个),问是否能构造一条同时满足连续两个0不能再一起和连续 ...

  2. jsp报An error has occurred. See error log for more details. Argument not valid错误

    An error has occurred. See error log for more details. Argument not valid 翻译过来是:一个错误已经发生.看到更多的细节错误日志 ...

  3. 1、VGG16 2、VGG19 3、ResNet50 4、Inception V3 5、Xception介绍——迁移学习

    ResNet, AlexNet, VGG, Inception: 理解各种各样的CNN架构 本文翻译自ResNet, AlexNet, VGG, Inception: Understanding va ...

  4. datagrid 行号问题综合

    1.datagrid 左侧行号设置宽度 : 到 easyui.css 中修改 .datagrid-cell-rownumber 中 width 的宽度.

  5. Python:条件判断

    条件控制:if...elif...else if condition_1: statement_1 elif condition_2: statement_2 else: statement_3 判断 ...

  6. Java 高阶 —— try/catch

    // try catch 在 for 循环外 try { for(int i = 0; i < max; i++) { String myString = ...; float myNum = ...

  7. Java并发实现线程阻塞原语LockSupport

    LockSupport 和 CAS 是Java并发包中很多并发工具控制机制的基础,它们底层其实都是依赖Unsafe实现.LockSupport是用来创建锁和其他同步类的基本线程阻塞原语. 1.Lock ...

  8. bzoj 4300 绝世好题 —— 思路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4300 记录一下 mx[j] 表示以第 j 位上是1的元素结尾的子序列长度最大值,转移即可. ...

  9. Android开发者的四大工具

    1. Basic4Android Basic4Android是Android平台上一个简单而又强大的可视化快速应用开发工具,它可被用来开发和测试数据库通信,甚至可以被用来开发2D的即时游戏! 主要特性 ...

  10. ceph学习之pool

    pool是ceph存储数据时的逻辑分区,它起到namespace的作用.其他分布式存储系统,比如Mogilefs.Couchbase.Swift都有pool的概念,只是叫法不同.每个pool包含一定数 ...