ACM--Game Prediction

Game Prediction

Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 1522, Accepted users: 1375
Problem 10019 : No special judgement

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

Problem Source

Bei jing 2002

分析

这个题感觉还是蛮有趣的,最开始想的有点复杂,但是通过对题目的分析就发现,我们判断回合是否自己会赢,是从大到小来判断,如果我们拥有的是nm-n到nm的牌,那我们就会赢n个回合,因为别人不会有比我们更大的牌(题目中清晰表明不存在相同的牌)。

并且只需判断是否有人拥有比我们大的牌就可以了,因此n除了初始化下面的x以外(求得最大牌点数),没有其他作用;

所以我们就从大到小进行比较,设置假设别人的牌每一局最大是x,初始化为m*n;
当我们拥有的时候,代表比较的牌的值x减1(下一次就应该与x-1比较);
当我们没有拥有的时候,且拥有的牌小于x的时候,代表比较的牌值减2(下一次就应该与x-2比较),因为这时候我们拥有的牌最大只能是x-1,那么下一局,我们假设的对方最大牌面就应该是x-2;

AC 代码

#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int j=0;
	int m,n;
	while(cin>>m>>n&&(m!=0||n!=0)) {
		int *a=new int[n];
		for(int i=0; i<n; i++) {
			cin>>a[i];
		}//输入完成
		sort(a,a+n);//排序
		int x=m*n;//x为最大值的牌
		int result=n;//最大可能赢n个回合
		for(int i=n-1; i>=0; i--) {
			if(a[i]<x) {//不拥有x值的牌,且拥有的牌小于x
				result--;//输掉一个回合
				x-=2;//x-2!!!!!!
			} else
				x--;//如果有该牌,减一即可
		}
		j++;//计算样例
		cout<<"Case "<<j<<": ";
		
		cout<<result<<'\n';
		delete[]a;
	}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MORE_77

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值