poj1323 Game Prediction

来源:互联网 发布:成本管控流程优化 编辑:程序博客网 时间:2024/04/30 11:16

Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10475 Accepted: 5046

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 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张牌,每轮牌面最大的人赢(牌面只可能是1~M*N中的一个数且不重复),给出一个人的牌,求其至少能够赢的局数。

二、解题思路

 这个题目的思路比较简单,由于人数和牌数比较少,所以直接暴力解,以第一个样例进行分析,用一个bool类型的数组。标记我手上有的牌为true,表格如下:

10 9 8 7 6 5 4 3 2 1
✔ ✔ ● ✔ ● ● ● ● ✔ ✔
✔本人 ● 对手

 显然当本人为7时,对手可能有牌面为8可以赢过我,以此类推,所以可以用一个int类型记录对手目前拥有的比本人最大的牌还要大的牌的数目,当遇到我拥有的大牌的时候就消耗一张大牌,假如此时对手没有比本人还要大的牌,那么这一轮本人绝对胜利。
#include<cstring>#include<cstdio>using namespace std;int main(){    int m,n,i,j,tmp,count=1;    bool cards[2050];    while(scanf("%d%d",&m,&n) && m&&n){        memset(cards,false,sizeof(cards));        for(i=0;i<n;i++){            scanf("%d",&j);            cards[j]=true;        }        int large_cards=0,ans=0;        for(i=m*n;i>0;i--){            if(!cards[i]) large_cards++;            else{                if(large_cards==0) ans++;                else large_cards++;            }        }        printf("Case %d: %d\n", count, ans);        count++;    }    return 0;}
原创粉丝点击