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. SQLSERVER SQL性能优化

      1.选择最有效率的表名顺序(只在基于规则的优化器中有效)      SQLSERVER的解析器按照从右到左的顺序处理FROM子句中的表名,因此FROM子句中写在最后的表(基础表driving ta ...

  2. 有个数组 我现在需要把数组里面的值按照n个一组,赋予一个新的数组

    有个数组  我现在需要把数组里面的值按照七个一组,赋予一个新的数组

  3. swap, 不用临时变量如何做到交换a与b

    固定思维通常是需要一个临时变量temp,如果没有这个临时变量呢,其实也不复杂,:) inline void swap(int &a, int &b) /*C用指针吧*/ { a = a ...

  4. CentOS7 minimal 没有netstat命令

    在CentOS 7 minimal中使用netstat 时,发现显示如下,明显没有了netstat 命令 [root@localhost ~]# netstat -a -bash: netstat: ...

  5. Mysql 查看连接数,状态,最大并发数

    MySQL: ERROR 1040: Too many connections”的异常情况,造成这种情况的一种原因是访问量过高,MySQL服务器抗不住,这个时候就要考虑增加从服务器分散读压力:另一种原 ...

  6. hadoop生态搭建(3节点)-01.基础配置

    # 基础配置# ==================================================================node1 vi /etc/hostname nod ...

  7. STM32CubeMx配置SPI注意的一个问题

    这样配置SPI引脚 然后这样配置SPI参数 生成立这样的配置代码 /* SPI2 init function */static void MX_SPI2_Init(void){ /* SPI2 par ...

  8. python继续函数-练习(2017-8-3)

    写函数,计算传入字符串中[数字].[字母].[空格] 以及 [其他]的个数 def detection(p): intcount = 0 strcount = 0 othercount = 0 spa ...

  9. u-boot.bin生成过程分析

    ELF格式“u-boot”文件的生成规则如下,下面对应Makefile的执行过程分别分析各个依赖. $(obj)u-boot: depend version $(SUBDIRS) $(OBJS) $( ...

  10. C++常量(const)的使用

    #include <iostream> using namespace std; class MyClass { public: int GetValue() const ; int Ge ...