Game Prediction
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10120 | Accepted: 4860 |
Description
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.
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?20) and n (1?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.
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 5 1 7 2 10 9 6 11 62 63 54 66 65 61 57 56 50 53 48 0 0
Sample Output
Case 1: 2 Case 2: 4
Source
【题意】
总共n*m张面值为1..n*m的扑克,n个人,每个人m张扑克,一共m轮,每轮每人出一张扑克,最大的人获胜,给出你的扑克,问你起码能赢多少局
【输入】
多组数据
第一行为n、m,若为两个0表示数据结束
接下来一行m个数字,表示自己的手牌
【输出】
对于每组数据,输出一个数字表示起码能赢多少局
#include<iostream>#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<numeric>
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <sstream> //基于字符串的流
#include <utility> //STL 通用模板类
#include <complex.h> //复数处理
#include <fenv.h> //浮点环境
#include <inttypes.h> //整数格式转换
#include <stdbool.h> //布尔环境
#include <stdint.h> //整型环境
#include <tgmath.h> //通用类型数学宏
#define L(a,b,c) for(int a = b;a >= c;a --)
#define M(a,b,c) for(int a = b;a < c;a ++)
#define N(a,b) memset(a,b,sizeof(a));
const int MAX=100000000;
const int MIN=-MAX;
typedef int T;
typedef double D;
typedef char C;
using namespace std;
int a[100010];
int main()
{
int n,m;
int t=0;
while(~scanf("%d%d",&n,&m))
{
if(n==0&&m==0)
break;
M(i,1,m+1)
scanf("%d",&a[i]);
sort(a+1,a+m+1);
int sum=0,ans=0; ///sum用来判断当前数的前面自己没有的数,ans用来统计自己可能赢得情况
for(int i=m*n; i>=1,m>=1; i--)
{
if(a[m]!=i) ///比较是否第m个数与i相同,相同用sum累加
sum++;
else
{
if(sum)
sum--;
else
ans++;
m--;
}
}
printf("Case %d: %d\n",++t,ans);
}
return 0;
}