poj 1323 Game Prediction

来源:互联网 发布:js缺少对象,怎样调试 编辑:程序博客网 时间:2024/05/16 13:11

Game Prediction
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9532 Accepted: 4556

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

Source

Beijing 2002


(转)  M个人,每人N张牌,每轮比较谁出的牌大,最大者为胜。现在给定M和N,以及你的牌,要求输出你至少能确保获得几轮的胜利

举个例子吧,第二个样例
6 11
62 63 54 66 65 61 57 56 50 53 48
首先对手中的牌做一个降序排列,即
66 65 63 62 61 57 56 54 53 50 48
66和65肯定必胜,63因为外面有64,所以不能保证必胜,62必胜(因为64已经被63消耗掉了),61必胜(同理),后面都都没有必胜可能了

用一个数组记录所有的牌,从自己的牌开始出牌,自己每出一次牌,就扫描比自己大的牌,如果有比自己大的牌,就出出来,否则自己赢的次数加1


#include <iostream>using namespace std;int main(){    int n,m,ans,count=0;    int a[51];    int flag;    int visited[1010];   //标记所有的牌是否已出    while (cin>>n>>m && (n || m))    {        ans=0;        memset(visited, 1, sizeof(visited));        for (int i=0;i<m ; i++)        {            cin>>a[i];        }        sort(a, a+m, greater<int>());        for (int i=0; i<m; i++)        {            flag=1;            visited[a[i]]=0;          //出自己的牌            for (int j=m*n; j>a[i]; j--)   //扫描是否有比自己大的牌            {                if(visited[j])   //扫描是否有比自己大的牌,并且没有出过                {                    visited[j]=0;   //把大牌出了                    flag=0;                    break;                }            }            if(flag)  //没有大牌            {                ans++;  //没有大牌,自己又赢了            }        }        cout<<"Case "<<++count<<": ";        cout<<ans<<endl;    }    return 0;}



0 0
原创粉丝点击