HDU 1338 Game Prediction

来源:互联网 发布:android 源码 蓝牙可见 编辑:程序博客网 时间:2024/04/27 17:23

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1338
Game Prediction

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1206 Accepted Submission(s): 672

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

题目大意:
有n个人,每人手里有m张牌
牌的点数从1到m*n,且各不相同
总共进行 n 轮比赛,m 个人都选择自己的一张卡片来进行比较,点数最大的在该轮比赛中胜利。
给出 你所拥有的 n 张卡片的点数,求你在这场游戏中最少能赢多少轮比赛。

思路:
将整个数组置为0,所给数置为1
以排序后的每个数为标记,若从数组最后遍历到该数前有一坐标为0,
则置为1,并跳出当前循环;若均为1,则一定能赢,计数加一

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;int main(){    int n,m,cas=0;    while(scanf("%d%d",&n,&m)!=EOF)    {        cas++;        if(n==0&&m==0)            break;        int my[60]={0},num[1010]={0};        for(int i=1;i<=m;i++)        {            int item;            scanf("%d",&item);            num[item]=1;            my[i]=item;        }        sort(my,my+m+1);        /*for(int i=0;i<=m;i++)            printf("%d ",my[i]);*/        int count=0;        for(int i=m;i>0;i--)        {            int flag=0;            for(int j=n*m;j>my[i];j--)            {                if(num[j]==0)                {                    num[j]=1;                    flag=1;                    break;                }            }            if(flag==0)            {                //printf("%d\n",my[i]);                count++;            }            else                continue;        }        printf("Case %d: %d\n",cas,count);    }    return 0;}

//因为sort的长度卡了一会,心塞……

0 0
原创粉丝点击