ZOJ 1362 Game Prediction

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 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

 

题目意思是:有M个人玩一个游戏,每个人抓N张牌,最大为N*M;

给出你抓到的牌数。叫你求你最少能嬴几次?就是与别人比较时最少几张牌在round中比其他人都大。

我们想到的一个办法是取max=N*M,与自己的牌比较,相等就累加1,要避免的问题是:max不能和你有的牌相等。

这个题目,还有种做法,就是用标记位,我试了下,没AC,就用下面的CODE好了


#include<stdio.h>//用个max做游标与数组比较,==的时候k+1.
void sort(int t[],int n)//选择法排序  直接拉模板
{
   int i,j,k,temp;
    for (i=0;i<n;i++)
        {
    k=i;
   for (j=i;j<n;j++)
    if (t[j]>t[k]) k=j;
   temp=t[i];
   t[i]=t[k];
   t[k]=temp;
        }
}

 
int main()
{
 int M,N;
 int k=0,max;//k计数,最少能赢的次数,max:标记位用来存放每次比较值
 int a[1000];//a数组用来存放抓到的牌
 int rub[50];//用来存放数组中被删去的数,之前WA:数组设太小!!!
 int Case=1;
 while(scanf("%d%d",&M,&N)&&M&&N)
 {
  int i,j=0;
  //rub[20]=0;
  max=M*N;
  k=0;
  for(i=0;i<N;i++)
   scanf("%d",&a[i]);
   sort(a,N);
   //for(i=0;i<N;i++)printf("%d ",a[i]); 检验排序效果!
   for(i=0;i<N;i++)
   {
    if(max==a[i]) {k++;max--;}//符合要求,k自增
    else
    {
     rub[j++]=a[i];
     max--;
     for(int p=0;p<=j;p++)//循环放里面!!!!!!!!!!!!!!!!!!!
     if(rub[p]==max)
     max--;
    }
    
   }
   printf("Case %d: %d/n",Case++,k);   
 }
 return 0;
}

 

你可能感兴趣的:(ZOJ 1362 Game Prediction)