1054Game Prediction小结
来源:互联网 发布:企业网站开源cms 编辑:程序博客网 时间:2024/06/18 05:29
1.题目描述:
Suppose there are M people, including you, playing a special card game. At the beginning, each player receives N cards. The pip of a card is a positive integer which is at most N*M. And there are no two cards with the same pip. During a round, each player chooses one card to compare with others. The player whose card with the biggest pip 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.
Given your cards received at the beginning, write a program to tell the maximal number of rounds that you may at least win during the whole game.
Input
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 pips 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.
Output
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.
Sample Input
2 51 7 2 10 96 1162 63 54 66 65 61 57 56 50 53 480 0
Sample Output
Case 1: 2Case 2: 42.题目概述及思路:M个人,每个人N张牌,牌的点数从M*N向下,没有重复的点数。每次出一张牌,谁的点大,谁这轮就赢了。给你一套牌,看最少能赢多少轮。思路很简单,去除掉给出的点数,然后构造一套最好的牌。
3.具体实现:
#include <iostream>#include <string>using namespace std;//练习下快忘了的快排void quick_sort(int s[], int l, int r){ if (l < r) { int i = l, j = r, x = s[l]; while (i < j) { while(i < j && s[j] <= x) j--; if(i < j) s[i++] = s[j]; while(i < j && s[i] > x) i++; if(i < j) s[j--] = s[i]; } s[i] = x; quick_sort(s, l, i - 1); quick_sort(s, i + 1, r); }}int main(){ int r1[60],r2[60]; int m,n,max,i,j; int count=0; int cas=1; while(true) { cin>>m>>n; if(m==0&&n==0) break; for(i=0; i<n; i++) cin>>r1[i]; quick_sort(r1,0,n-1); for(i=0; i<60; i++) r2[i]=0; int flag=0; i=0; count=0; max=m*n; while(i<n) { flag=0; for(j=0; j<n; j++) { if(r1[j]==max) flag=1; } if(flag==0) { r2[i]=max; i++; } max--; } i=0; count=0; j=0; for(i=0; i<n; i++) { if(r1[i]>r2[j]) { count++; } else { j++; } } cout<<"Case "<<cas<<": "<<count<<endl; cas++; } return 0;}
- 1054Game Prediction小结
- Game Prediction
- Game Prediction
- Game Prediction
- Game Prediction
- Game Prediction
- Game Prediction
- pku1323 Game Prediction
- FZU 1113 Game Prediction
- POJ 1323 Game Prediction
- 1323 Game Prediction
- ZOJ 1362 Game Prediction
- poj 1323 Game Prediction
- poj1323(Game Prediction)
- poj 1323 Game Prediction
- poj1323 Game Prediction 贪心
- POJ-1323-Game Prediction
- poj 1323 Game Prediction
- 二分图最大匹配-增广路-hdu2063-过山车
- extern C作用总结
- nginx启动报错 nginx: error while loading shared libraries: libpcre.so.1
- C 语言有什么奇技淫巧?
- 真彩图转256色图
- 1054Game Prediction小结
- Java 集合类详解2
- HDU 5119 Happy Matt Friends(简单二维dp)
- 集训小记 7
- debian下利用aptitude安装指定版本的软件
- 2、类、对象、方法
- 黑马程序员——按钮操作
- majority element
- Tomcat内核之ASCII解码的表驱动模式