poj----Game Prediction

来源:互联网 发布:黑马java 全套百度云 编辑:程序博客网 时间:2024/06/05 02:14

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. 

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. 

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: 4
题意:有n个人,每个人有m张牌,第二行就是我的牌,牌的大小是从1到n*m的,求我自己最少可以赢几张牌
#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;int a[60],flag[1050];int main(){    int i,m,n,now,max;    int cases=0;    while(scanf("%d%d",&m,&n)!=EOF&&(m||n))    {        priority_queue<int> q;        cases++;        now=0;        memset(flag,0,sizeof(flag));        for(i=0; i<n; i++)        {            scanf("%d",&a[i]);            q.push(a[i]);            flag[a[i]]=1;        }        for(i=m*n; i>0&&!q.empty(); i--)        {            if(flag[i]==1)//我有i这张牌,我赢一次            {                q.pop();                now++;            }            else if(flag[i]==2);//我曾经有过i这张牌,但是对手有比我还大的,所以我这张牌被干掉了,呜呜            else//我没i这张牌,也就是对手有,所以我手里最大的一张牌(但比i小)被干掉了            {                int x=q.top();                q.pop();                flag[x]=2;            }        }        printf("Case %d: %d\n",cases,now);    }    return 0;}


0 0
原创粉丝点击