How many rounds of winning
How many rounds of winning
- 描述
-
When douglasren came home,he reunioned with his classmates.So M students arrived at the scene. So long they did not see each other,they were very pleased.Then,they decided to play a card game to promote their feelings.At the beginning ,each player receives N cards.All the cards has a different digit,which is at most M*N and not less than 1,And there are no two cards with the same digit,During a round, each player chooses one card to compare with others. The player whose card with the biggest digit wins the round, and then the next round begins. After N rounds, when all the cards of each player have been chosen, the player who has won the most rounds is the winner of the game.
When douglasren received his cards at the beginning,he want to know the maximal number of rounds that he may at least win during the whole game.Can you tell him the result? - 输入
- The input consists of several test cases. The first line of each case contains two integers M (2<=M<=20) and N (1<=N<=50), representing the number of players and the number of cards each player receives at the beginning of the game, respectively. This followed by a line with n positive integers, representing the digit of cards you received at the beginning. Then a blank line follows to separate the cases.
The input is terminated by a line with two zeros. - 输出
- For each test case, output a line consisting of the test case number followed by the number of rounds you will at least win during the game.
- 样例输入
-
2 5 1 7 2 10 9 6 11 62 63 54 66 65 61 57 56 50 53 48 0 0
- 样例输出
-
Case 1: 2 Case 2: 4
- 提示
- scanf() is faster than cin.
//模拟题
# include<stdio.h> # include<algorithm> using namespace std; int main() { int nPerson,nCase,leap,sign,cnt,i,t,con=1; int s[52]; while(scanf("%d %d",&nPerson,&nCase)&&(nPerson||nCase)) { leap=0; sign=0; cnt=0; for(i=0;i<nCase;i++) scanf("%d",&s[i]); sort(s,s+nCase); t=nPerson*nCase; for(i=nCase-1;i>=0;i--) { if(s[i]==t) { sign++; t--;//记录对比的数 } else { if(sign>0) { cnt+=sign;//cnt为一定能赢的数目 sign=0;//还原 } sign-=t-s[i]-1;//记录后面的数和下一个数的差值 t=s[i]-1;//记录下一个对比的数 if(i<=-sign)break;//如果差值大于了i,后面的就不用算了 } } if(sign>0)cnt+=sign;//完善最后一次漏掉的判断 printf("Case %d: %d\n",con++,cnt); } return 0; }
浙公网安备 33010602011771号