Game Prediction
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 11814   Accepted: 5701

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

从最大n*m 记录自己没有的牌为count, count表示能大于自己的可能输掉的情况.
如果碰到自己有的牌,count>0时消耗掉一张大于自己的牌, count=0时, 表示没有比自己大的牌 ans++;

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring> using namespace std; int main()
{
int n, m, num, max, count, ans, Case=;
bool data[];
while(scanf("%d%d", &n, &m) && n && m)
{
max = n*m;
count=;
ans=;
memset(data, , sizeof(data));
for(int i=; i<m; i++)
{
scanf("%d", &num);
data[num] = true;
}
getchar();getchar();
for(int i=max; i>; i--)
{
if(!data[i])
count++;
else if(data[i])
{
if(count==)
ans++;
else
count--;
}
} printf("Case %d: %d\n", Case++, ans);
}
return ;
}
												

poj_1323 Game Prediction 贪心的更多相关文章

  1. poj1323-Game Prediction(贪心思想)

    贪心的思想:尽量的从最大值找起.然后在剩余之中,再从最大值找起. 一,题意: M个人,每人N张牌,每轮比较谁出的牌大,最大者为胜.现在给定M和N,以及你的牌,要求输出你至少能确保获得几轮的胜利 从&q ...

  2. POJ 1323 Game Prediction#贪心

    (- ̄▽ ̄)-* //既然是求最少能胜几次 //说明对方是要尽可能让我输 //但为了避免浪费,对方会用比我的牌大的牌中的最小pip的牌来击败我 #include<iostream> #in ...

  3. POJ动态规划题目列表

    列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...

  4. HDU 1338 Game Prediction【贪心】

    解题思路: 给出 n  m 牌的号码是从1到n*m 你手里的牌的号码是1到n*m之间的任意n个数,每张牌都只有一张,问你至少赢多少次 可以转化为你最多输max次,那么至少赢n-max次 而最多输max ...

  5. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  6. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. E - 不爱学习的lyb HDU - 1789(贪心策略)

    众所周知lyb根本不学习.但是期末到了,平时不写作业的他现在有很多作业要做. CUC的老师很严格,每个老师都会给他一个DDL(deadline). 如果lyb在DDL后交作业,老师就会扣他的分. 现在 ...

  2. CyclicBarrier是如何成为一个"栅栏"的

    CyclicBarrier是一种类似于栅栏的存在,意思就是在栅栏开放之前你都只能被挡在栅栏的一侧,当栅栏移除之后,之前被挡在一侧的多个对象则同时开始动起来. 1. 如何使用CyclicBarrier ...

  3. markdown多张图片并排显示

    在markdown中,目前,让图片像这样并排居中的方式主要是两种: ![](https://img2018.cnblogs.com/blog/1735896/202001/1735896-202001 ...

  4. spring中BeanPostProcessor之二:CommonAnnotationBeanPostProcessor(01)

    在上篇博客中分享了InstantiationAwareBeanPostProcessor接口中的四个方法,分别对其进行了详细的介绍,在文末留下了一个问题,那就是postProcessPropertie ...

  5. 测试老司机都在用的表白神器你会吗?-Fiddler之AutoResponse线上调试

    一.Fiddler在线调试功能和表白神器介绍 ​ 在以往的工作中,线上有bug,就需要把文件弄到本地来改,但经常会碰见本地环境又和线上不一样,导致调试困难,闭着眼睛改好之后传到线上去看对不对,不对的话 ...

  6. 汇编 RET 和 CALL

    https://blog.csdn.net/u013018721/article/details/51264199 1.我们先来实践一下 ret 指令 DATA SEGMENT A DB 12H B ...

  7. Python常见数据结构-List列表

    Python list基本特点 列表是一种有序集合,可以随时添加和删除元素. 序列中的每个元素都分配一个数字 - 它的位置. 列表的数据项不需要具有相同的类型. 创建一个列表,只要把逗号分隔的不同的数 ...

  8. mysql--> find your databases' local position

    1. find file:  "my.ini" 2.Using ctrl+F  find string "datadir" then you can see y ...

  9. Python设计模式(6)-原型模式

    import copy class Employee: age = 10 employee_name = 'zxc' class Company: name = '' num = 0 def __in ...

  10. spark sql createOrReplaceTempView registerTempTable

    createOrReplaceTempView2.x版本以上. registerTempTable1.5.x val data1 = dataSelect1(sqlContext, sparkMode ...