POJ1323 Game Prediction(贪心算法训练)
来源:互联网 发布:饥荒联机百科全书 mac 编辑:程序博客网 时间:2024/04/30 13:05
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10475 Accepted: 5046 View Code
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.
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.
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
一、题目大意
有M个人,一人N张牌,每轮牌面最大的人赢(牌面只可能是1~M*N中的一个数且不重复),给出一个人的牌,求其至少能够赢的局数。
二、解题思路
这个题目的思路比较简单,由于人数和牌数比较少,所以直接暴力解,以第一个样例进行分析,用一个bool类型的数组。标记我手上有的牌为true,表格如下:
✔本人 ● 对手
显然当本人为7时,对手可能有牌面为8可以赢过我,以此类推,所以可以用一个int类型记录对手目前拥有的比本人最大的牌还要大的牌的数目,当遇到我拥有的大牌的时候就消耗一张大牌,假如此时对手没有比本人还要大的牌,那么这一轮本人绝对胜利。
三、具体代码
1 #include <cstdio> 2 #include <cstring> 3 4 int main(){ 5 int m, n, i, j, tmp, count=1; 6 bool cards[1050]; 7 while(scanf("%d%d", &m, &n) && m && n){ 8 memset(cards, false, sizeof(cards)); 9 for(i=0; i<n; i++){10 scanf("%d", &j);11 cards[j] = true;12 }13 int large_cards=0, ans=0;14 for(i=m*n; i>0; i--){15 if(!cards[i]) large_cards++;16 else{17 if(large_cards == 0) ans++;18 else large_cards--;19 }20 }21 22 printf("Case %d: %d\n", count, ans);23 count++;24 }25 26 return 0;27 }
0 0
- POJ1323 Game Prediction(贪心算法训练)
- poj1323 Game Prediction 贪心
- POJ1323 Game Prediction(贪心)
- POJ1323 Game Prediction(贪心)
- POJ1323 Game Prediction(贪心)
- poj1323(Game Prediction)
- POJ1323 Game Prediction
- POJ1323------Game Prediction
- poj1323 Game Prediction
- 【POJ1323】Game Prediction 博弈,或者说贪心(本博客用栈处理)
- Game Prediction(贪心)
- Game Prediction(贪心)
- 【贪心】Game Prediction
- POJ | 1323 Game Prediction | 贪心
- 贪心 hdu-1338-Game Prediction
- HDU 1338 Game Prediction 贪心
- POJ 1323 Game Prediction 贪心
- POJ 1323 Game Prediction(贪心)
- MFC下绘制曲线工具Teechart使用
- 编写linux驱动所用到的头文件
- 人工神经网络
- 每日打卡 2017.04.13 计算几何
- POJ1700 Crossing River(贪心算法训练)
- POJ1323 Game Prediction(贪心算法训练)
- POJ3624 Charm Bracelet(典型01背包问题)
- POJ1017 Packets(贪心算法训练)
- 嵌入式实验EX1:Kahn Process Networks and Synchronous Data Flows
- Opencv 中的结构体CvScalar
- nginx实现反向代理和负载均衡
- Java中的引用类型和垃圾回收
- Spring学习-25:Spring中的JDBC Template(JDBC模板):设置参数到属性文件
- 面试知识点6:MySQL中InnoDB的一级索引、二级索引