Game Prediction
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8956   Accepted: 4269

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
题目大意:M个人,每人N张牌,每轮比较谁出的牌大,最大者为胜。现在给定M和N,以及你的牌,要求输出你至少能确保获得几轮的胜利。
解题方法:先对所有的牌进行从大到小排序,每次出牌之前看比当前牌大的牌是否出完,如果出完则结果加一并把当前那张牌出完,如果没有出完则把没出的最大的那张和当前的牌出了。
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std; bool cmd(const int &a, const int &b)
{
return a > b;
} int main()
{
int visited[];
int card[];
int m, n, ans, nCase = ;
bool flag = false;
while(scanf("%d%d", &m, &n) != EOF && m != && n != )
{
ans = ;
memset(visited, , sizeof(visited));
for (int i = ; i < n; i++)
{
scanf("%d", &card[i]);
}
sort(card, card + n, cmd);
for (int i = ; i < n; i++)
{
flag = true;
//从后向前查找比当前牌大的牌是否出完
for (int j = m * n; j > card[i]; j--)
{
//找到没出的最大的那张,出牌
if (!visited[j])
{
flag = false;
visited[j] = ;
break;
}
}
//当前的牌出了
visited[card[i]] = ;
//如果比当前牌大的牌全部出完,结果加一
if (flag)
{
ans++;
}
}
printf("Case %d: %d\n", ++nCase, ans);
}
return ;
}
 

POJ 1323 Game Prediction的更多相关文章

  1. POJ 1323 Game Prediction#贪心

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

  2. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  3. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  4. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  5. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  6. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  7. POJ题目分类(转)

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  8. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

随机推荐

  1. 动态生成带参数的html标签

     "<button onclick='watchClick("+'"'+row.BOXNO + '","'+ row.VOY_NO+'" ...

  2. 后台登录验证(Tokens/JSON Web Tokens(JWT) 的认证机制)

    sessionid不支持跨域,浏览器也不能禁止cookie(禁止以后sessionid还有什么用) 单点登录问题,即时SessionID一样,也无法跨域获取到数据 占坑

  3. Codeforces Round #321 (Div. 2) D Kefa and Dishes(dp)

    用spfa,和dp是一样的.转移只和最后一个吃的dish和吃了哪些有关. 把松弛改成变长.因为是DAG,所以一定没环.操作最多有84934656,514ms跑过,实际远远没这么多. 脑补过一下费用流, ...

  4. springboot 测试

    本次测试使用的是springboot 中的测试 1.(对service 的测试)下面的测试.将会启动容器进行测试 @RunWith(SpringRunner.class) @SpringBootTes ...

  5. 2018.4.1 Ubuntu16.04 下配置Tomcat服务器以及设置dingshi启动

    Tomcat自启动的设置技巧 以root用户登录系统: cd /etc/rc.d/init.d/ vi tomcat #!/bin/sh # # tomcat: Start/Stop/Restart ...

  6. apropos linux

    Apropos adj. 恰当的,关于,就...而言 adv. 顺便地,恰当地 All my suggestions apropos the script were accepted. 我所有有关该剧 ...

  7. fence_vmware_soap UnicodeEncodeError

    执行如下命令 fence_vmware_soap -z -l administrator@vsphere.local -p 2wsx@QAZ -a 10.0.2.200 -o list --ssl-i ...

  8. Service Unavailable HTTP Error 503. The service is unavailable.

    原因: public void SetCurrentType(string[] projTypes) { _ProjTypes = _ProjTypes; } 确保没有无限递归或无限循环

  9. 遍历Map的两种方式

    取出map集合中所有元素的方式一:keySet()方法. 可以将map集合中的键都取出存放到set集合中.对set集合进行迭代.迭代完成,再通过get方法对获取到的键进行值的获取. Set keySe ...

  10. Object-C知识点 (五) NSObject的继承关系

    这篇文章主要介绍常用的继承自NSObject的类,方便朋友们查看和面试前查看使用!!! 结构图: 更多内容--> 博客导航 每周一篇哟!!! 有任何关于iOS开发的问题!欢迎下方留言!!!或者邮 ...