Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly nmovements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball?
The first line of the input contains an integer n (1 ≤ n ≤ 2·109) — the number of movements made by the operator.
The second line contains a single integer x (0 ≤ x ≤ 2) — the index of the shell where the ball was found after n movements.
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
4
2
1
1
1
0
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
- During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
- During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
- During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
- Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
题意:三个位置上的东西 0 1 2 先0/1交换后1/2交换 告诉你交换n次之后的位置判断初始位置
题解:%6 水
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #include <stack> 7 #include <queue> 8 #include <cmath> 9 #include <map> 10 #define ll __int64 11 #define mod 1000000007 12 #define dazhi 2147483647 13 using namespace std; 14 int m[10][10]; 15 int main() 16 { 17 m[0][0]=0; 18 m[1][1]=0; 19 m[2][2]=0; 20 m[2][3]=0; 21 m[1][4]=0; 22 m[0][5]=0; 23 24 m[1][0]=1; 25 m[0][1]=1; 26 m[0][2]=1; 27 m[1][3]=1; 28 m[2][4]=1; 29 m[2][5]=1; 30 31 m[2][0]=2; 32 m[2][1]=2; 33 m[1][2]=2; 34 m[0][3]=2; 35 m[0][4]=2; 36 m[1][5]=2; 37 ll n; 38 ll x; 39 scanf("%I64d",&n); 40 n=n%6; 41 scanf("%I64d",&x); 42 printf("%d ",m[x][n]); 43 return 0; 44 }
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite n-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if n = 3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.
Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3and 1 to give Sherlock two flicks.
Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains n digits — Sherlock's credit card number.
The third line contains n digits — Moriarty's credit card number.
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
3
123
321
0
2
2
88
00
2
0
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
题意:两组n位数字a,b 对于相同的某一位i进行比较 a[i]<b[i] 则a的flicks值增加1 a[i]>b[i] 则b的flicks值增加1
任意排列两组的n位数字 问max(a_flicks) min(b_flicks)
题解:两种不同的贪心思路 具体看代码。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #include <stack> 7 #include <queue> 8 #include <cmath> 9 #include <map> 10 #define ll __int64 11 #define mod 1000000007 12 #define dazhi 2147483647 13 using namespace std; 14 char a[1005]; 15 char b[1005]; 16 int mp[5][20]; 17 int main() 18 { 19 int n; 20 memset(mp,0,sizeof(mp)); 21 scanf("%d",&n); 22 getchar(); 23 scanf("%s",a); 24 //cout<<a<<endl; 25 scanf("%s",b); 26 for(int i=0;i<n;i++) 27 mp[1][a[i]-'0']++; 28 for(int i=0;i<n;i++) 29 mp[2][b[i]-'0']++; 30 int exm1=0; 31 int ans1=0; 32 for(int i=0;i<=9;i++) 33 { 34 exm1+=mp[1][i]; 35 if(exm1>=mp[2][i]) 36 { 37 exm1-=mp[2][i]; 38 } 39 else 40 { 41 ans1+=(mp[2][i]-exm1); 42 exm1=0; 43 } 44 } 45 int exm2=mp[2][9]; 46 int ans2=0; 47 for(int i=8;i>=0;i--) 48 { 49 if(exm2>=mp[1][i]) 50 { 51 ans2+=mp[1][i]; 52 exm2=exm2-mp[1][i]; 53 } 54 else 55 { 56 ans2+=exm2; 57 exm2=0; 58 } 59 exm2+=mp[2][i]; 60 } 61 printf("%d %d ",ans1,ans2); 62 63 return 0; 64 }