Game Prediction
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 11814   Accepted: 5701

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

从最大n*m 记录自己没有的牌为count, count表示能大于自己的可能输掉的情况.
如果碰到自己有的牌,count>0时消耗掉一张大于自己的牌, count=0时, 表示没有比自己大的牌 ans++;

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring> using namespace std; int main()
{
int n, m, num, max, count, ans, Case=;
bool data[];
while(scanf("%d%d", &n, &m) && n && m)
{
max = n*m;
count=;
ans=;
memset(data, , sizeof(data));
for(int i=; i<m; i++)
{
scanf("%d", &num);
data[num] = true;
}
getchar();getchar();
for(int i=max; i>; i--)
{
if(!data[i])
count++;
else if(data[i])
{
if(count==)
ans++;
else
count--;
}
} printf("Case %d: %d\n", Case++, ans);
}
return ;
}
												

poj_1323 Game Prediction 贪心的更多相关文章

  1. poj1323-Game Prediction(贪心思想)

    贪心的思想:尽量的从最大值找起.然后在剩余之中,再从最大值找起. 一,题意: M个人,每人N张牌,每轮比较谁出的牌大,最大者为胜.现在给定M和N,以及你的牌,要求输出你至少能确保获得几轮的胜利 从&q ...

  2. POJ 1323 Game Prediction#贪心

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

  3. POJ动态规划题目列表

    列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...

  4. HDU 1338 Game Prediction【贪心】

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

  5. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  6. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. 多线程学习笔记(五)---- 在JDK文档的使用

    1.前言 我们经常在JDK文档中见到一些类上的介绍说,该类是"安全的"."不安全"."效率高"."效率低"的词眼.这里, ...

  2. JSP+Struts2+JDBC+Mysql实现的校园宿舍管理系统

    项目简介 项目来源于:https://gitee.com/passenger134/javaweb-sushe 本系统基于JSP+Struts2+JDBC+Mysql的校园宿舍管理系统.该系统没有使用 ...

  3. java中的动手动脑

    1.关于构造函数的问题 为什么上面的代码不能通过编译? 因为当你没有定义构造函数时,java编译器在编译时会自动生成一个无参的构造函数,上面的代码就可以进行执行了.但是当你顶一个构造函数时,编译器将不 ...

  4. Python爬虫系列(三):requests高级耍法

    昨天,我们更多的讨论了request的基础API,让我们对它有了基础的认知.学会上一课程,我们已经能写点基本的爬虫了.但是还不够,因为,很多站点是需要登录的,在站点的各个请求之间,是需要保持回话状态的 ...

  5. spark sql createOrReplaceTempView registerTempTable

    createOrReplaceTempView2.x版本以上. registerTempTable1.5.x val data1 = dataSelect1(sqlContext, sparkMode ...

  6. Go语言的GPM调度器是什么?

    我是平也,这有一个专注Gopher技术成长的开源项目「go home」 导读 相信很多人都听说过Go语言天然支持高并发,原因是内部有协程(goroutine)加持,可以在一个进程中启动成千上万个协程. ...

  7. getline()和get()的使用区别

    一.getline和get()的使用区别: 首先这两个函数都读取下一行输入,直到到达换行符:但是getline()函数会丢弃换行符,而get()将换行符保留在输入序列中 二.getline()函数的使 ...

  8. MVC学习的心路历程

    2020/4/17 之前接触过三层架构,但是没有接触过mvc,所以有点蒙,所以现在在一步步构建思路. 1.了解MVC的发展,做一个简单的项目.

  9. 统计子串数量,Python基础

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:陈YL PS:如有需要Python学习资料的小伙伴可以加点击下方链接自 ...

  10. 基于netty实现rpc框架-spring boot客户端

    上篇讲了RPC服务端的实现.原理就是解析netty通道数据拿到类.方法及入参等信息,然后通过java反射机制调用本地接口返回结果.没有用到很复杂的技术. 这篇我们将客户端的实现.说白了客户端的任务很简 ...