Anton likes to play chess, and so does his friend Danik.
Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played.
The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' if Danik won the i-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes).
6
ADAAAA
Anton
7
DDDAADA
Danik
6
DADADA
Friendship
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
题意:水
题解:
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<map> 6 #define __int64 ll 7 using namespace std; 8 int n; 9 char a; 10 int s=0,b=0; 11 int main() 12 { 13 scanf("%d",&n); 14 s=0; 15 b=0; 16 getchar(); 17 for(int i=1; i<=n; i++) 18 { 19 scanf("%c",&a); 20 if(a=='A') 21 s++; 22 else 23 b++; 24 } 25 if(s>b) 26 cout<<"Anton"<<endl; 27 if(s<b) 28 cout<<"Danik"<<endl; 29 if(s==b) 30 cout<<"Friendship"<<endl; 31 return 0; 32 }
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
5 1 3 4
800
1 1 1 1
256
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
题意:水
题解:
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<map> 6 #define ll __int64 7 using namespace std; 8 ll a,b,c,d; 9 int main() 10 { 11 scanf("%I64d %I64d %I64d %I64d",&a,&b,&c,&d); 12 ll minx=0; 13 minx=min(a,min(c,d)); 14 ll ling=0; 15 ll exm=max(ling,a-minx); 16 ll minx1=min(exm,b); 17 cout<<minx*256+minx1*32<<endl; 18 return 0; 19 }
Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.
Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions.
- Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs bi manapoints and changes the preparation time of each potion to ai instead of x.
- Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs di manapoints and instantly create ci potions.
Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.
Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.
The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·109, 1 ≤ m, k ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.
The second line of the input contains two integers x and s (2 ≤ x ≤ 2·109, 1 ≤ s ≤ 2·109) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.
The third line contains m integers ai (1 ≤ ai < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.
The fourth line contains m integers bi (1 ≤ bi ≤ 2·109) — the number of manapoints to use the i-th spell of the first type.
There are k integers ci (1 ≤ ci ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that ci are not decreasing, i.e. ci ≤ cj if i < j.
The sixth line contains k integers di (1 ≤ di ≤ 2·109) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that di are not decreasing, i.e. di ≤ dj if i < j.
Print one integer — the minimum time one has to spent in order to prepare n potions.
20 3 2
10 99
2 4 3
20 10 40
4 15
10 80
20
20 3 2
10 99
2 4 3
200 100 400
4 15
100 800
200
In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).
In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200.
题意:
题解:枚举第一种魔法 二分第二种魔法 取最优解
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<map> 6 #define ll __int64 7 using namespace std; 8 ll n,m,k; 9 ll x,s; 10 struct node 11 { 12 ll w; 13 ll cost; 14 } N[200005],M[200005],zha[200005]; 15 bool check(int xx,ll cc) 16 { 17 if(M[xx].cost<=cc) 18 return true; 19 else 20 return false; 21 } 22 int main() 23 { 24 scanf("%I64d %I64d %I64d",&n,&m,&k); 25 scanf("%I64d %I64d",&x,&s); 26 N[0].w=x; 27 N[0].cost=0; 28 M[0].w=0; 29 M[0].cost=0; 30 for(int i=1; i<=m; i++) 31 scanf("%I64d",&N[i].w); 32 for(int i=1; i<=m; i++) 33 scanf("%I64d",&N[i].cost); 34 for(int i=1; i<=k; i++) 35 scanf("%I64d",&M[i].w); 36 for(int i=1; i<=k; i++) 37 scanf("%I64d",&M[i].cost); 38 ll ans=n*x; 39 for(int i=0; i<=m; i++) 40 { 41 if((s-N[i].cost)>=0){ 42 int l=0,r=k,mid; 43 int aaa=0; 44 while(l<=r) 45 { 46 mid=(l+r)/2; 47 if(check(mid,s-N[i].cost)) 48 { 49 aaa=mid; 50 l=mid+1; 51 } 52 else 53 { 54 r=mid-1; 55 } 56 } 57 if(M[aaa].w>=n) 58 ans=0; 59 else 60 ans=min(ans,N[i].w*(n-M[aaa].w)); 61 } 62 } 63 printf("%I64d ",ans); 64 return 0; 65 }
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.
The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.
Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move.
Help Anton and write the program that for the given position determines whether the white king is in check.
Remainder, on how do chess pieces move:
- Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.
- Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.
- Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap".
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces.
The second line contains two integers x0 and y0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king.
Then follow n lines, each of them contains a character and two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — type of the i-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.
The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.
2
4 2
R 1 1
B 1 5
YES
2
4 2
R 3 3
B 1 5
NO
Picture for the first sample:

Picture for the second sample:

题意:国际象棋中 判断king是否被check
题解:模拟 找的8个方向最近的棋子
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<map> 6 #define ll __int64 7 using namespace std; 8 int n; 9 ll x,y; 10 ll xx[500005],yy[500005]; 11 char a[500005]; 12 int main() 13 { 14 scanf("%d",&n); 15 scanf("%I64d %I64d",&x,&y); 16 a[0]='#'; 17 for(int i=1;i<=n;i++){ 18 getchar(); 19 scanf("%c %I64d %I64d",&a[i],&xx[i],&yy[i]);} 20 int s1=0,s2=0,s3=0,s4=0,s5=0,s6=0,s7=0,s8=0; 21 ll minx=1e10; 22 for(int i=1;i<=n;i++) 23 { 24 if(xx[i]==x&&yy[i]>y){ 25 if(minx>yy[i]){ 26 s1=i; 27 minx=yy[i]; 28 } 29 } 30 } 31 minx=-1e10; 32 for(int i=1;i<=n;i++) 33 { 34 if(xx[i]==x&&yy[i]<y){ 35 if(minx<yy[i]){ 36 s2=i; 37 minx=yy[i]; 38 } 39 } 40 } 41 minx=1e10; 42 for(int i=1;i<=n;i++) 43 { 44 if(xx[i]>x&&yy[i]==y){ 45 if(minx>xx[i]){ 46 s3=i; 47 minx=xx[i]; 48 } 49 } 50 } 51 minx=-1e10; 52 for(int i=1;i<=n;i++) 53 { 54 if(xx[i]<x&&yy[i]==y){ 55 if(minx<xx[i]){ 56 s4=i; 57 minx=xx[i]; 58 } 59 } 60 } 61 minx=1e10; 62 for(int i=1;i<=n;i++) 63 { 64 if(xx[i]>x&&yy[i]>y&&(xx[i]-yy[i])==(x-y)){ 65 if(minx>yy[i]){ 66 s5=i; 67 minx=yy[i]; 68 } 69 } 70 } 71 minx=-1e10; 72 for(int i=1;i<=n;i++) 73 { 74 if(xx[i]<x&&yy[i]<y&&(xx[i]-yy[i])==(x-y)){ 75 if(minx<yy[i]){ 76 s6=i; 77 minx=yy[i]; 78 } 79 } 80 } 81 minx=-1e10; 82 for(int i=1;i<=n;i++) 83 { 84 if(xx[i]>x&&yy[i]<y&&(xx[i]+yy[i])==(x+y)){ 85 if(minx<yy[i]){ 86 s7=i; 87 minx=yy[i]; 88 } 89 } 90 } 91 minx=1e10; 92 for(int i=1;i<=n;i++) 93 { 94 if(xx[i]<x&&yy[i]>y&&(xx[i]+yy[i])==(x+y)){ 95 if(minx>yy[i]){ 96 s8=i; 97 minx=yy[i]; 98 } 99 } 100 } 101 if((s1!=0&&a[s1]!='B')||(s2!=0&&a[s2]!='B')||(s3!=0&&a[s3]!='B') 102 ||(s4!=0&&a[s4]!='B')||(s5!=0&&a[s5]!='R') 103 ||(s6!=0&&a[s6]!='R')||(s7!=0&&a[s7]!='R')||(s8!=0&&a[s8]!='R')) 104 cout<<"YES"<<endl; 105 else 106 cout<<"NO"<<endl; 107 return 0; 108 }