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. js使用my97插件显示当前时间,且select控制计算时间差

    做页面需要两个时间输入框一个显示当前时间,一个显示之前的时间,并且需要一个select下拉框控制两个时间输入框之间的差,效果如下图: 这里使用的是My97DatePicer,简单方便,引入my97插件 ...

  2. UVA 12171 (hdu 2771)sculptrue(离散化)

    以前对离散化的理解不够,所以把端点和区间区分来考虑但是做完这题以后有了新的认识: 先来看一个问题:给你以下的网格,你需要多少空间去存储红点区间的信息呢? 只需要图上所示的1,2,3,4个点就足够表示红 ...

  3. Android(java)学习笔记133:Eclipse中的控制台不停报错Can't bind to local 8700 for debugger

    [DDMS] Can't bind to local 8600 for debugger 改成 Under Window -> Preferences -> Android -> D ...

  4. HTML_3

    html列表 有序列表:在网页上定义一个有编号的内容列表可以用<ol>.<li>配合使用来实现,在网页上生成的列表,每条项目上按1.2.3编号,有序列表在实际开发中较少使用.代 ...

  5. Cenos7—安装

    1. 进入安装界面 2. 选择语言 3. 进行分区 4. 设置root密码

  6. java基础—object类

    一.Object类介绍

  7. 初涉网络流[EK&dinic]

    主要还是板子 Edmonds-Karp 从S开始bfs,直到找到一条到达T的路径后将该路径增广,并重复这一过程. 在处理过程中,为了应对“找到的一条路径把其他路径堵塞”的情况,采用了建反向弧的方式来实 ...

  8. 03 Django视图

    功能 接受Web请求HttpRequest,进行逻辑处理,与 M 和 T 进行交互,返回 Web 响应 HttpResponse 给请求者 示例项目的创建 创建项目 test3 django-admi ...

  9. Applied Nonparametric Statistics-lec1

    参考网址: https://onlinecourses.science.psu.edu/stat464/node/2 Binomial Distribution Normal Distribution ...

  10. STM32三种启动模式 boot0 boot1

    STM32三种启动模式对应的存储介质均是芯片内置的,它们是: 1)用户闪存=芯片内置的Flash.2)SRAM=芯片内置的RAM区,就是内存啦.3)系统存储器=芯片内部一块特定的区域,芯片出厂时在这个 ...