POJ1323 Game Prediction(贪心)

来源:互联网 发布:sublime text mac破解 编辑:程序博客网 时间:2024/04/30 15:22

题目:

Game Prediction
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 10972 Accepted: 5284

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

[Submit]   [Go Back]   [Status]   [Discuss]

思路:

有m个人玩牌,每个人有n张牌,所以牌的总数是m*n,然后在第二行题目给出了你拥有的牌的号码,比赛规则是每个人依次出牌,最后数字大的那个人获胜

我们把自己手中的牌先标记一下,然后从m*n~1找,如果没有被标记过,那么要记录一下比你大的牌的数量,如果当前的牌被标记过,然后看一下比你大的牌的数量是不是为0,如果是的话你赢一局,不是的话比你大的牌的数量-1

代码:

#include<cstdio>#include<cstring>#include<string>#include<set>#include<iostream>#include <cmath>#include<stack>#include<queue>#include<vector>#include<algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define debug() puts("what the fuck!!!")#define N (1010)#define ll long longusing namespace std;int num[10000];int vis[10000];int main(){int m, n,q=1;while ( scanf ( "%d%d", &m, &n ) && ( m || n ) ){mem ( num, 0 );mem ( vis, 0 );int pai = 0,ans=0;for ( int i = 1; i <= n; i++ ){scanf ( "%d", &num[i] );vis[num[i]] = 1;}for ( int i = m * n; i >= 1; i-- ){if ( !vis[i] ){pai++;}else{if(pai==0)ans++;elsepai--;}}printf("Case %d: %d\n",q++,ans);}return 0;}