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. JavaScript空假值及其判断

    一.javaScript五种空值和假值 分别为undefined,null,false,"",0,这五个值的共同点是在执行if语句时都会执行false分支,执行对应的非语句的时候都 ...

  2. hihoCoder #1050 : 树中的最长路

    题意: 求出树上最长路径的长度,并返回. 思路: 刚看到数据<=10^5,假如是单分支的树,那么有5万层,就不能递归,那就用桟实现, 那就要将长度信息保存在另开的数组中,很麻烦!!这题专门给递归 ...

  3. UVA 10891 Game of Sum (决策优化)

    这是一个零和博弈,最高得分只和序列以及谁先手有关. d[i][j],表示i到j的序列当前取的这个人的最高得分,转移以后状态是新的区间和另一个人取,从中取最小值. 决策的最小值也可递推. #includ ...

  4. AWVS12 防止反复注册

    以管理员权限运行cmd,输入以下内容: cacls "C:\ProgramData\Acunetix\shared\license." /t /p everyone:r 如图:

  5. caffe parse_log.sh

    画loss曲线需要用到此shell脚本 #!/bin/bash # Usage parse_log.sh caffe.log # It creates the following two text f ...

  6. Java动画 重力弹球 如鹏游戏引擎 精灵 设计一个小球加速落地又减速弹起并反复直到停止的Java程序

    package com.swift; import com.rupeng.game.GameCore; public class BouncingBall implements Runnable { ...

  7. 配置淘宝镜像,不使用怪异的cnpm

    npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm. ...

  8. 头文件string与string.h的区别

    在C++中,#include<iostream>与#include<iostream.h>的区别,前者要使用更新的编译器(其实大部分编译器多比较前卫了,出了有些搞嵌入式的用变态 ...

  9. pandas中的随机排序和抽样

    1.随机重排序 使用take()随机排序 如: df.take([54])   #采取索引为54的数据 可以借助np.random.permutation()函数随机排序 permutation()函 ...

  10. java版RSA工具类

    /** * RSA算法加密/解密工具类 */ public class RSAUtils { private static final Logger LOGGER = LoggerFactory.ge ...