POJ 1323-Game Prediction--贪心

Game Prediction

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9552   Accepted: 4566

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

一道简单的贪心,说实话我是看了题解才明白的,sad 我总感觉贪心很难。。

有n个打牌,每人m张牌,牌的编号从1--n*m 然后比大小,谁的牌大谁赢,主要就是记录自己手中的牌的问题,可以设一个数组a,初始化为0,每输入自己手中的一张牌号x,令a[x]=1;以此来代表自己手中的牌,将牌从大到小遍历,如果单前牌是自己手中的牌的牌那么win++;否则win--;(如果是别人的牌那么你这局肯定输了)设一个max变量记录win的最大值就是答案。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
bool my[10010];
int main()
{
	int n,m,i,ca=0,x;
	while(cin>>n>>m)
	{
		if(!n&&!m) break;
		memset(my,0,sizeof(my));
		for(i=0;i<m;i++)
		{
			cin>>x;
			my[x]=1;
		}
		int win=0,max=0;
		for(i=m*n;i>0;i--)
		{
			if(my[i])
			{
				win++;
				if(win>max)
					max=win;
			}
			else
				win--;
		}
		cout<<"Case "<<++ca<<": "<<max<<endl;
	}
	return 0;
}

POJ 1323-Game Prediction--贪心,布布扣,bubuko.com

时间: 2024-08-10 18:20:45

POJ 1323-Game Prediction--贪心的相关文章

贪心/poj 1323 Game Prediction

1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 int m,n,lose,x; 6 bool flag[1010],v[1010]; 7 bool cmp(int a,int b) 8 { 9 return a>b; 10 } 11 int main() 12 { 13 scanf("%d%d",&m,&n

POJ 1323 Game Prediction

Game Prediction Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10627   Accepted: 5121 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

poj 2431 Expedition (贪心+优先队列)

Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6890   Accepted: 2065 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to

POJ 3085 Quick Change (贪心)

Quick Change Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5801   Accepted: 4175 Description J.P. Flathead's Grocery Store hires cheap labor to man the checkout stations. The people he hires (usually high school kids) often make mistak

POJ 1659 Frogs&#39; Neighborhood (贪心)

题意:中文题. 析:贪心策略,先让邻居多的选,选的时候也尽量选邻居多的. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring>

POJ 1328 Radar Installation 贪心题解

本题是贪心法题解,不过需要自己观察出规律,这就不容易了,很容易出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 按照x轴大小排序 2 从最左边的点循环,首先找到最小x轴的圆 3 以这个圆判断可以包括右边的多少个圆,直到不可以包括下一个点,那么继续第2步,画一个新圆. 看代码吧,应该很清晰直观的了. 效率是O(n),虽然有嵌套循环,但是下标没有重复,一遍循环就可以了,故此是O(n). #include <stdio.h> #include <cmath> #incl

POJ 3190 Stall Reservations(贪心+优先队列优化)

Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obviously, FJ must create a reserv

Poj 1328 Radar Installation 贪心

题目链接:http://poj.org/problem?id=1328 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 52768   Accepted: 11867 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the othe

HDU 1338 Game Prediction 贪心

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. Du

POJ 3190 Stall Reservations贪心

POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obvi