A-Find the Spy(zoj 3860)
Whoooa! There is a spy in Marjar University. All we know is that the spy has a special ID card. Please find him out!
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains a integer N (3 <= N <= 100), which describes that there are N students need to be checked.
The second line contains N integers indicating the ID card number of N students. All ID card numbers are 32-bit integers.
Output
For each test case, output the ID card number which is different from others.
Sample Input
3 10 1 1 1 1 1 1 1 1 6 1 3 9 9 8 5 90016 90016 90016 2009 90016
Sample Output
6 8 2009
题意:第一题水题,给你n个数求其中不一样的那个数。
做法:直接做~
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define inf 0x0f0f0f0f
#define LL long long
using namespace std;
int main()
{
int t,i,j;
int num[105];
int n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&num[i]);
sort(num,num+n);
if(num[0]!=num[1])
{
printf("%d\n",num[0]);
}
else
printf("%d\n",num[n-1]);
}
}
B-Valid Pattern Lock(zoj 3861)
Pattern lock security is generally used in Android handsets instead of a password. The pattern lock can be set by joining points on a 3 × 3 matrix in a chosen order. The points of the matrix are registered in a numbered order starting with 1 in the upper left corner and ending with 9 in the bottom right corner.
A valid pattern has the following properties:
- A pattern can be represented using the sequence of points which it's touching for the first time (in the same order of drawing the pattern). And we call those points as active points.
- For every two consecutive points A and B in the pattern representation, if the line segment connecting A and B passes through some other points, these points must be in the sequence also and comes before A and B, otherwise the pattern will be invalid.
- In the pattern representation we don't mention the same point more than once, even if the pattern will touch this point again through another valid segment, and each segment in the pattern must be going from a point to another point which the pattern didn't touch before and it might go through some points which already appeared in the pattern.
Now you are given n active points, you need to find the number of valid pattern locks formed from those active points.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains an integer n (3 ≤ n ≤ 9), indicating the number of active points. The second line contains n distinct integers a1, a2, … an (1 ≤ ai ≤ 9) which denotes the identifier of the active points.
Output
For each test case, print a line containing an integer m, indicating the number of valid pattern lock.
In the next m lines, each contains n integers, indicating an valid pattern lock sequence. The m sequences should be listed in lexicographical order.
Sample Input
1 3 1 2 3
Sample Output
4 1 2 3 2 1 3 2 3 1 3 2 1
做法:用了排列函数next_permutation函数来做,首先把n个数字从小到大拍好,然后这个函数的复杂度是n!,然后写好里面的条件就行。
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define inf 0x0f0f0f0f
#define LL long long
using namespace std;
struct ans1
{
int a[10];
}ans[400000];
int main()
{
int t,i,j,sum;
int num[10];
int vis[10];
int n,flag;
scanf("%d",&t);
while(t--)
{
sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&num[i]);
sort(num,num+n);
do
{
memset(vis,inf,sizeof(vis));
flag=1;
for(i=0;i<n;i++)
{
vis[num[i]]=i;
}
if(vis[3]-vis[1]==1&&vis[2]>vis[1]&&vis[2]>vis[3])
flag=0;
if(vis[7]-vis[1]==1&&vis[4]>vis[1]&&vis[4]>vis[7])
flag=0;
if(vis[9]-vis[1]==1&&vis[5]>vis[1]&&vis[5]>vis[9])
flag=0;//1
if(vis[8]-vis[2]==1&&vis[5]>vis[8]&&vis[5]>vis[2])
flag=0;//2
if(vis[1]-vis[3]==1&&vis[2]>vis[1]&&vis[2]>vis[3])
flag=0;
if(vis[7]-vis[3]==1&&vis[5]>vis[3]&&vis[5]>vis[7])
flag=0;
if(vis[9]-vis[3]==1&&vis[6]>vis[3]&&vis[6]>vis[9])
flag=0;//3
if(vis[6]-vis[4]==1&&vis[5]>vis[4]&&vis[5]>vis[6])
flag=0;//4
if(vis[4]-vis[6]==1&&vis[5]>vis[4]&&vis[5]>vis[6])
flag=0;//6
if(vis[1]-vis[7]==1&&vis[4]>vis[1]&&vis[4]>vis[7])
flag=0;
if(vis[3]-vis[7]==1&&vis[5]>vis[3]&&vis[5]>vis[7])
flag=0;
if(vis[9]-vis[7]==1&&vis[8]>vis[9]&&vis[8]>vis[7])
flag=0;//7
if(vis[2]-vis[8]==1&&vis[5]>vis[2]&&vis[5]>vis[8])
flag=0;//8
if(vis[1]-vis[9]==1&&vis[5]>vis[1]&&vis[5]>vis[9])
flag=0;
if(vis[3]-vis[9]==1&&vis[6]>vis[3]&&vis[6]>vis[9])
flag=0;
if(vis[7]-vis[9]==1&&vis[8]>vis[9]&&vis[8]>vis[7])
flag=0;//9
if(flag==1)
{
for(i=0;i<n;i++)
ans[sum].a[i]=num[i];
sum++;
}
}while(next_permutation(num,num+n));
printf("%d\n",sum);
for(i=0;i<sum;i++)
{
for(j=0;j<n;j++)
{
if(j!=0)
printf(" ");
printf("%d",ans[i].a[j]);
}
printf("\n");
}
}
}
E-Quiz for EXO-L(zoj 3864)
Exo (Korean: 엑소; Chinese:爱咳嗽; often stylized as EXO) is a Chinese-South Korean boy band based in Seoul, South Korea. Formed by SM Entertainment in 2011, the group consists of twelve members separated into two subgroups, EXO-K and EXO-M, performing music in Korean and Mandarin, respectively. The group officially debuted on April 8, 2012, with Suho, Baekhyun, Chanyeol, D.O, Kai, and Sehun under the Korean subgroup while Xiumin, Luhan, Kris, Lay, Chen, and Tao are under the Mandarin group. Kris filed a lawsuit against S.M. to be removed from the group, and Luhan followed suit in October 2014. The band now promotes with 10 members since mid-October 2014, which consists of 8 Korean and 2 Chinese members.
In their first album, each member of EXO has a kind of super power. For example, Tao can control time and Lay has a super power of healing. The badges are the symbols of their super powers. Each member of EXO has an unique badge. The following table shows the shapes of their badges.
Baekhyun | Chanyeol | Chen | D.O |
Kai | Kris | Lay | Luhan |
Sehun | Suho | Tao | Xiumin |
EXO’s official fanclub name has been announced to be EXO-L. EXO-L is short for EXO-LOVE, L being the letter between M and K in the alphabet, signifying all the fans' love for both EXO-K and EXO-M of EXO, and also holds the meaning of 'EXO and the fans are one' like their team slogan 'WE ARE ONE.'
You should help an EXO-L pass a quiz about image recognition. The quiz requires a program to recognize the badges. The input is one of the above 12 images with rotation, and the output should be the owner of the badge in the image. The badge is rotated at an unknown angle. And each image is a square matrix. The badges will never touch or exceed the boundary of the image.
Since the images are large, we will compress the images. Each pixel in the image is either 1(white) or 0(black) after binarization. The compress method is simple:
- Concatenate the pixels in the row first order to a string.
- Split the string to some runs with same characters, and two adjacent runs have different characters.
- Output the length of each run.
For example, an image in size 6×6:
111111 100101 100011 110111 101001 111111
- Concatenate the pixels in the row first order, then we can get
111111100101100011110111101001111111
- The runs are
1111111 00 1 0 11 000 1111 0 1111 0 1 00 1111111
- So the result of compressed images is
7 2 1 1 2 3 4 1 4 1 1 2 7
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains 2 integers n and m. n is the size of the square image. m is the number of the runs in the compressed images. (100≤ n ≤ 900)
The second line contains m positive integers, indicating the length of the each runs in the compressed image. (The sum of the integers is n2).
Output
For each case, output the owner of the badge in one line. Your output should be formated as one of following words: "Suho", "Baekhyun", "Chanyeol", "D.O", "Kai", "Sehun", "Xiumin", "Luhan", "Kris", "Lay", "Chen", and "Tao".
Sample Input
2
100 443
1445 1 99 2 97 3 97 4 6 1 88 5 5 2 88 5 4 4 86 6 4 4 73 1 12 6 3 6 72 4 8 6 5 5 72 6 6 6 5 6 72 7 3 6 6 6 12 1 59 16 7 6 9 3 60 14 8 6 6 6 61 13 9 6 3 7 65 12 7 16 8 1 45 3 10 12 5 15 6 4 45 5 9 14 3 12 6 6 45 6 8 15 2 9 9 5 47 5 7 17 1 7 10 6 47 6 6 17 2 3 13 5 48 6 5 18 17 6 49 5 5 8 1 10 5 3 8 5 50 6 3 8 5 7 3 7 6 5 50 6 3 8 7 18 2 5 52 5 3 7 10 23 52 6 2 7 13 20 52 6 3 6 15 17 53 7 2 5 19 15 49 10 2 5 21 16 44 12 2 4 24 17 38 12 6 3 25 18 34 12 6 4 26 7 1 13 31 9 7 6 25 7 5 10 34 4 6 9 25 7 8 5 46 8 25 8 58 9 25 7 59 8 25 8 59 8 25 7 48 4 7 8 26 7 8 2 35 9 5 8 25 6 7 7 33 11 3 8 25 4 6 11 35 18 25 3 5 15 36 16 25 3 3 15 40 17 21 4 2 14 44 17 19 5 2 10 49 17 16 6 2 8 51 20 13 6 2 6 52 23 11 7 2 4 53 5 2 18 8 8 2 5 51 6 5 8 2 7 6 7 3 5 51 5 8 4 5 9 2 8 4 4 50 6 17 18 5 5 49 5 13 3 2 18 5 5 48 6 11 5 3 16 7 5 47 6 9 8 2 16 7 5 47 5 7 11 3 14 9 4 46 3 8 14 4 13 9 4 45 1 8 16 6 14 8 2 54 16 9 13 62 9 3 5 8 15 60 6 6 5 8 16 58 5 9 5 7 5 2 9 58 2 12 5 6 6 5 7 72 5 5 5 8 5 72 5 4 6 11 2 73 3 5 5 87 3 5 5 87 3 5 4 89 1 6 4 97 3 97 2 98 2 1445
100 451
1449 2 96 4 96 5 94 6 93 6 94 5 93 6 93 6 10 4 78 7 7 13 72 6 6 18 80 21 62 2 14 24 58 3 14 26 55 3 13 15 6 8 54 4 10 20 8 5 51 5 8 25 8 3 51 4 7 29 7 3 49 5 6 31 7 2 48 5 6 15 4 14 7 1 48 5 5 15 9 11 54 6 4 15 12 10 53 5 4 16 14 8 53 5 3 16 16 8 51 6 3 8 1 6 18 8 50 6 2 8 2 6 19 7 50 6 2 7 3 5 7 21 5 1 43 6 1 7 4 5 4 24 4 2 43 6 1 7 4 5 2 26 4 3 43 12 4 5 2 28 3 3 43 12 4 5 16 14 3 4 42 11 5 5 19 12 3 4 42 10 5 5 15 1 5 10 3 5 41 10 6 3 16 1 7 8 4 5 40 9 7 3 16 2 7 8 3 7 32 1 6 8 7 3 16 2 8 7 4 7 29 5 4 8 7 3 16 3 7 8 4 6 29 6 4 7 7 3 16 3 8 7 5 5 29 7 3 8 7 2 16 3 8 8 5 3 31 6 4 8 6 2 16 4 7 8 40 6 4 8 6 1 16 4 6 10 40 6 3 9 6 1 15 4 6 10 42 4 3 11 20 4 6 10 42 4 4 12 18 4 6 11 42 3 4 15 15 4 5 12 43 2 4 26 3 5 5 12 43 2 4 25 4 5 4 6 1 6 44 1 5 6 2 14 6 5 4 6 1 6 44 1 5 7 5 6 9 6 3 7 1 6 50 8 19 6 2 7 2 6 51 8 18 6 1 7 3 6 51 9 16 15 3 6 52 10 13 15 4 5 54 11 11 14 5 5 47 1 6 14 6 15 6 4 49 1 6 33 6 5 49 2 6 31 7 4 50 3 7 27 8 4 52 4 6 25 9 3 53 6 7 20 10 3 55 29 12 2 57 26 14 1 60 23 78 20 6 5 71 15 7 8 72 10 8 7 92 7 92 6 93 6 94 6 94 5 95 4 97 2 1448
Sample Output
Xiumin Sehun
Hint
The images in the sample input are visualized as:
Sample 1 | Sample 2 |
题意:一开始看到题目看不懂,感觉很难辨识出来。其实题目给我们是n*n个0或者1的表格,然后让我们求出所表示的图形是上面十二种图形中的哪一个。
做法:用bfs求出黑色和白色的连通块(用dfs好像爆栈了),然后分别记录,要注意的是当黑色块为5,白色块为2的时候恰好是有两种情况,这就是样例中的两个例子,然后我们就可以先输出sum(四块小的黑色块)/sum(最大的黑色块)的值,根据这个值来区分。
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define inf 0x0f0f0f0f
#define LL long long
using namespace std;
int sumb,sumw,n;
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
int s[1005][1005];
int s2[1005][1005];
struct node
{
int x,y;
int t;
}aa;
queue<node>q;
void bfsb(int xx,int yy,int &ss)
{
node tmp;
int nx,ny,x,y,i,t;
aa.x=xx;
aa.y=yy;
q.push(aa);
s[aa.x][aa.y]=1;
while(!q.empty())
{
tmp=q.front();
q.pop();
x=tmp.x;
y=tmp.y;
for(i=0;i<8;i++)
{
nx=x+dx[i];
ny=y+dy[i];
if(nx>=0&&nx<n&&ny>=0&&ny<n)
{
node temp;
if(s[nx][ny]==0)
{
s[nx][ny]=1;
temp.x=nx;
temp.y=ny;
ss++;
q.push(temp);
}
}
}
}
}
void bfsw(int xx,int yy)
{
node tmp;
int nx,ny,x,y,i;
aa.x=xx;
aa.y=yy;
q.push(aa);
s2[xx][yy]=0;
while(!q.empty())
{
tmp=q.front();
q.pop();
x=tmp.x;
y=tmp.y;
for(i=0;i<8;i++)
{
nx=x+dx[i];
ny=y+dy[i];
if(nx>=0&&nx<n&&ny>=0&&ny<n)
{
node temp;
if(s2[nx][ny]==1)
{
s2[nx][ny]=0;
temp.x=nx;
temp.y=ny;
q.push(temp);
}
}
}
}
}
int main()
{
int y,i,j,dx,dy;
int a,t,ss;
int kk[900];
int m;
scanf("%d",&t);
while(t--)
{
sumb=sumw=0;
dx=dy=0;
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%d",&a);
if(i%2==1)
{
while(a--)
{
s[dx][dy]=1;
s2[dx][dy]=1;
dy++;
if(dy==n)
{
dx++;
dy=0;
}
}
}
if(i%2==0)
{
while(a--)
{
s[dx][dy]=0;
s2[dx][dy]=0;
dy++;
if(dy==n)
{
dx++;
dy=0;
}
}
}
}
/* for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d",s2[i][j]);
printf("\n");
}*/
int ss;
while(!q.empty())
q.pop();
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(s[i][j]==0)
{
ss=1;
bfsb(i,j,ss);
//printf("**%d\n",ss);
kk[sumb++]=ss;
}
}
while(!q.empty())
q.pop();
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(s2[i][j]==1)
{
//printf("***%d %d\n",i,j);
sumw++;
bfsw(i,j);
}
}
// printf("*%d %d\n",sumb,sumw);
if(sumb==9&&sumw==2)
printf("Baekhyun\n");
if(sumb==5&&sumw==1)
printf("Chanyeol\n");
if(sumb==1&&sumw==3)
printf("Chen\n");
if(sumb==1&&sumw==2)
printf("D.O\n");
if(sumb==2&&sumw==13)
printf("Kai\n");
if(sumb==3&&sumw==1)
printf("Kris\n");
if(sumb==6&&sumw==2)
printf("Lay\n");
if(sumb==5&&sumw==8)
printf("Luhan\n");
if(sumb==5&&sumw==2)
{
int sum1,sum2;
sort(kk,kk+sumb);
sum1=kk[0]+kk[1]+kk[2]+kk[3];
if(sum1*1.0/kk[4]>=0.4)
printf("Xiumin\n");
else
printf("Sehun\n");
}
if(sumb==2&&sumw==8)
printf("Suho\n");
if(sumb==2&&sumw==4)
printf("Tao\n");
}
}
F-Superbot(zoj 3865)
Superbot is an interesting game which you need to control the robot on an N*M grid map.
As you see, it's just a simple game: there is a control panel with four direction left (1st position), right (2nd), up (3rd) and down (4th). For each second, you can do exact one of the following operations:
- Move the cursor to left or right for one position. If the cursor is on the 1st position and moves to left, it will move to 4th position; vice versa.
- Press the button. It will make the robot move in the specific direction.
- Drink a cup of hot coffee and relax. (Do nothing)
However, it's too easy to play. So there is a little trick: Every P seconds the panel will rotate its buttons right. More specifically, the 1st position moves to the 2nd position; the 2nd moves to 3rd; 3rd moves to 4th and 4th moves to 1st. The rotating starts at the beginning of the second.
Please calculate the minimum time that the robot can get the diamond on the map.
At the beginning, the buttons on the panel are "left", "right", "up", "down" respectively from left to right as the picture above, and the cursor is pointing to "left".
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains three integers N, M (2 <= N, M <= 10) and P (1 <= P <= 50), which represent the height of the map, the width of the map and the period that the panel changes, respectively.
The following lines of input contains N lines with M chars for each line. In the map, "." means the empty cell, "*" means the trap which the robot cannot get in, "@" means the initial position of the robot and "$" means the diamond. There is exact one robot and one diamond on the map.
Output
For each test case, output minimum time that the robot can get the diamond. Output "YouBadbad" (without quotes) if it's impossible to get the diamond.
Sample Input
4 3 4 50 @... ***. $... 5 5 2 ..... ..@.. .*... $.*.. ..... 2 3 1 *.@ $.* 5 5 2 ***** ..@.. ***** $.... .....
Sample Output
12
4
4
YouBadbad
Hint
For the first example:
0s: start
1s: cursor move right (cursor is at "right")
2s: press button (robot move right)
3s: press button (robot move right)
4s: press button (robot move right)
5s: cursor move right (cursor is at "up")
6s: cursor move right (cursor is at "down")
7s: press button (robot move down)
8s: press button (robot move down)
9s: cursor move right (cursor is at "left")
10s: press button (robot move left)
11s: press button (robot move left)
12s: press button (robot move left)
For the second example:
0s: start
1s: press button (robot move left)
2s: press button (robot move left)
--- panel rotated ---
3s: press button (robot move down, without changing cursor)
4s: press button (robot move down)
For the third example:
0s: start
1s: press button (robot move left)
--- panel rotated ---
2s: press button (robot move down)
--- panel rotated ---
3s: cursor move left (cursor is at "right")
--- panel rotated ---
4s: press button (robot move left)
题意:机器要从@点走到$点,题目规定一开始的方向是上下左右记为{1,2,3,4},然后我们可以选择按当前的第一个数字所代表的方向走一步,或者选择左移方向即变为{2,3,4,1},或者右移方向即方向变为{4,1,2,3},或者可以选择什么都不做,需要注意的是每隔p秒钟方向就会右移一次,让我们求出最小步数。
做法:BFS即可,需要注意的是要把方向也写到结构体中,然后每个点走到过的次数用js数组来记录,如走过超过10次则不用再push。
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define inf 0x0f0f0f0f
#define LL long long
using namespace std;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int ll[10];
char s[205][205];
int vis[205][205],h,n,m,tt,p;
int js[20][20];
int ans;
struct node
{
int x, y;
int rr[10];
int time;
int dr;
int w;
}st[10],aa,bb;
queue<node> q;
bool check(int x, int y)
{
if(x>=0 && x<h && y>=0 && y<n)
return true;
return false;
}
int BFS(int a)
{
int x, y, z, t, i,f,j;
int dr,w;
int rr[10];
int xx;
node temp;
aa.x=st[a].x;
aa.y=st[a].y;
aa.time=0;
aa.dr=1;
aa.w=0;
aa.rr[0]=1,aa.rr[1]=2,aa.rr[2]=3,aa.rr[3]=4;
vis[aa.x][aa.y]=1;
q.push(aa);
while(!q.empty())
{
node tmp = q.front();
q.pop();
x = tmp.x;
y = tmp.y;
t = tmp.time;
js[x][y]++;
//if(w>50||t>500)
// vis[x][y]=1;
for(i=0;i<4;i++)
rr[i]=tmp.rr[i];
if(t!=0&&t%p==0)
{
int kk=1;
ll[0]=rr[3];
for(i=0;i<3;i++)
ll[kk++]=rr[i];
temp.time=t;
temp.x=x;
temp.y=y;
temp.w=w;
temp.dr=ll[0];
for(i=0;i<4;i++)
{
rr[i]=ll[i];
}
}
dr =rr[0];
for(j = 0; j < 4; j++)
{
if(j==0)
{
int kk=1;
ll[0]=rr[3];
for(i=0;i<3;i++)
ll[kk++]=rr[i];
temp.time=t+1;
temp.x=x;
temp.y=y;
temp.w=w;
temp.dr=ll[0];
for(i=0;i<4;i++)
temp.rr[i]=ll[i];
if(js[x][y]<100)
q.push(temp);
}
if(j==1)
{
int kk=0;
ll[3]=rr[0];
for(i=1;i<4;i++)
ll[kk++]=rr[i];
temp.time=t+1;
temp.x=x;
temp.y=y;
temp.w=w;
temp.dr=ll[0];
for(i=0;i<4;i++)
temp.rr[i]=ll[i];
if(js[x][y]<100)
q.push(temp);
}
if(j==2)
{
temp.time=t+1;
temp.x=x;
temp.y=y;
temp.w=w+1;
temp.dr=dr;
for(i=0;i<4;i++)
temp.rr[i]=rr[i];
if(js[x][y]<100)
q.push(temp);
}
if(j==3)
{
int nx,ny;
if(dr==1)
nx=x,ny=y-1;
if(dr==2)
nx=x,ny=y+1;
if(dr==3)
nx=x-1,ny=y;
if(dr==4)
nx=x+1,ny=y;
if(check(nx,ny)&&vis[nx][ny]==0&&s[nx][ny]!='*')
{
// printf("***%d %d %c %d dr:%d\n",nx,ny,s[nx][ny],t+1,dr);
if(s[nx][ny]=='$')
return t+1;
vis[nx][ny]=1;
temp.time=t+1;
temp.x=nx;
temp.y=ny;
temp.w=w;
temp.dr=dr;
for(i=0;i<4;i++)
temp.rr[i]=rr[i];
if(js[nx][ny]<100)
q.push(temp);
}
}//printf("*******good\n");
}
}
return -1;
}
int main()
{
int i,j,kk,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&h,&n,&p);
scanf("\n");
for(i=0;i<h;i++)
{
gets(s[i]);
for(j=0;j<n;j++)
{
if(s[i][j]=='@')
{
st[1].x=i;
st[1].y=j;
}
}
}
// printf("%d %d\n",st[1].x,st[1].y);
memset(vis,0,sizeof(vis));
memset(js,0,sizeof(js));
while(!q.empty())
q.pop();
ans=BFS(1);
if(ans==-1)
printf("YouBadbad\n");
else
printf("%d\n",ans);
}
}
H-Earthstone: Easy Version
Earthstone is a famous online card game created by Lizard Entertainment. It is a collectible card game that revolves around turn-based matches between two opponents. Players start the game with a substantial collection of basic cards, but can gain rarer and more powerful cards through purchasing packs of additional cards, or as rewards for competing in the arena. Card packs can be purchased with gold, an in-game currency rewarded for completing random daily quests and winning matches, or by using real money in the in-game store.
Each Earthstone battle is a one on one turn-based match between two opponents. During a player's turn, he can choose to play any of his cards and command the minions to attack targets. Those played cards will be placed on the table as they are 'summoned' as minions. Each card has two basic attributes:
- Attack Ai: If a minion attacks a character or was attacked, it will deal Ai points of damage to the opponent. A character whose attack value is zero cannot actively attack.
- Health Hi: The minion has Hi points of initial health. After being damaged, the minion's health will decrease by the corresponding damage value. The minion will be killed and discarded if its health is less than or equal to zero.If a minion attacks another minion, both of them will receive damage simultaneously.
Given two minions, please calculate the result if the first minion attacked the second one.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
There are four integers A1, H1, A2 and H2 (0 <= A1, A2 <=10, 1 <= H1, H2 <= 10), which are the attributes of two minions.
Output
For each test case, output "Invalid" (without quotes) if the first minion cannot attack, otherwise output the minions attributes as the format in input. If the minion is killed, output "Discard" instead (without quotes).
Sample Input
3 3 3 2 4 3 2 2 5 0 3 2 2
Sample Output
3 1 2 1 Discard 2 2 Invalid
Discard ,最后输出各自怪物的状态。
做法:水题,直接做。
#include <iostream> #include <cstdio> #include <climits> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <algorithm> #define esp 1e-6 #define inf 0x0f0f0f0f #define LL long long using namespace std; int main() { int t; int i,j; int a1,h1,a2,h2; scanf("%d",&t); while(t--) { scanf("%d%d%d%d",&a1,&h1,&a2,&h2); h1-=a2; h2-=a1; if(a1==0) { printf("Invalid\n"); continue; } if(h1<=0&&h2>0) { printf("Discard %d %d\n",a2,h2); continue; } if(h1>0&&h2<=0) { printf("%d %d Discard\n",a1,h1); continue; } if(h1<=0&&h2<=0) { printf("Discard Discard\n"); continue; } printf("%d %d %d %d\n",a1,h1,a2,h2); } }