http://acm.hdu.edu.cn/showproblem.php?pid=1338

Problem 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 <= m <= 20) and n (1 <= n <= 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
 
题解:贪心 排序
代码:

#include <bits/stdc++.h>
using namespace std; int N, M;
int num[55]; int main() {
int Case = 0;
while(~scanf("%d%d", &N, &M)) {
Case ++;
if(!N && !M) break;
for(int i = 1; i <= M; i ++) {
scanf("%d", &num[i]);
} int maxx = N * M;
int cnt = 0;
sort(num + 1, num + 1 + M);
for(int i = M; i >= 1; i --) {
if(num[i] >= maxx) {
cnt ++;
maxx --;
}
else maxx -= 2;
}
printf("Case %d: %d\n", Case, cnt);
}
return 0;
}

  

HDU 1338 Game Prediction的更多相关文章

  1. HDU 1338 Game Prediction【贪心】

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

  2. HDU 5923 Prediction

    这题是2016 CCPC 东北四省赛的B题, 其实很简单. 现场想到的就是正解, 只是在合并两个并查集这个问题上没想清楚. 做法 并查集合并 + 归并 对每个节点 \(u\), 将 \(u\) 到根的 ...

  3. HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B,并查集)

    题目链接  2016 CCPC东北地区大学生程序设计竞赛 B题 题意  给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这 ...

  4. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  5. hdu 5895 广义Fibonacci数列

    Mathematician QSC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  6. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. HDU 6153 A Secret 套路,求解前缀在本串中出现的次数

    http://acm.hdu.edu.cn/showproblem.php?pid=6153 首先相当于翻转两个串,然后求s2前缀在s1中出现的次数. 这是一个套路啦 首先把两个串结合起来,中间加一个 ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. BigDecimal运算(加、减、乘、除)

    public class BigDecimalOperation { private BigDecimalOperation(){ } public static BigDecimal add(dou ...

  2. hdu_2588_GCD

    The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the ...

  3. 字符串拼接在Oracle和mysql中的用法

    oracle拼接字符串 1.使用  '||' 或者 concat(参数1,参数2) select 'aa' || 'bb' || 'cc' from dual; 结果:aabbcc select co ...

  4. sql server,mysql,oracle平时用法的区别

    由于工作的原因,上家公司一直使用的oracle,后来接触了的几个项目,既有使用mysql的又有使用sqlserver,自己在使用sqlserver及mysql要实现某功能时,经常要在网上找来找去,所以 ...

  5. windows 下安装pyspider

    今天主要介绍一下在Windows下安装pyspider,pyspider是一款用python编写的网络爬虫框架,这个框架最好是在linux下运行,Windows下运行可能会出现兼容性问题,如果实在要在 ...

  6. PHP+AJAX开发幸运大转盘抽奖

    PHP+AJAX开发幸运大转盘抽奖,通过奖品库存.中奖次数来计算中奖概率 奖品设置 $prizes = array( 0 => array( "id" => 0, // ...

  7. vue笔记 介绍及安装 一

    Vue.js 是什么 Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层, ...

  8. requests模块基础

    requests模块 .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { bor ...

  9. Go语言使用百度翻译api

    Go语言使用百度翻译api 之前做过一个使用百度翻译api的工具,这个工具用于用户的自动翻译功能,是使用C#调用百度翻译api接口,既然在学习Go语言,那必然也是要使用Go来玩耍一番.这里我是这么安排 ...

  10. POJ-2421-Constructing Roads(最小生成树 普利姆)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26694   Accepted: 11720 Description The ...