HDU 1338 Game Prediction 贪心

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

Source

Asia 2002, Beijing (Mainland China)

题目意思:

有m个人,每个人有n张牌,牌点为在1~n*m中的不同的数。每回合每个人出一张牌,点数最大的那个人赢,给出A人初始时的n张牌的牌点,问A至少赢的次数。

思路: 看做两个人单挑,你有m张牌,我有m*(n-1)张牌,每次我都出比你大大一点的牌,如果没有,出最小的m张牌(可以忽略),不用担心什么的

上代码了:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 10005

int n,m;
int vis[N],a[N];

int main()
{
    int i,ca=0;
    while(~scanf("%d%d",&n,&m),n+m)
    {
        memset(vis,0,sizeof(vis));

        for(i=0;i<m;i++)
        {
            scanf("%d",&a[i]);
            vis[a[i]]=1;      //我手上没有的牌
        }

        int ans=0;
        sort(a,a+m);  //排序对方的牌

        int top; 

        for(i=m-1;i>=0;i--)  //这里for(i=0;i<m;i++) 也是一样正确的,不必纠结
        {
            for(top=a[i];;top++)
                if(!vis[top])
                 break;

            if(top<=n*m)
                vis[top]=1;  //出掉这张牌
            else
                ans++;    //没有比他大的,出最小牌(可以忽略出最小牌)
        }

        printf("Case %d: %d\n",++ca,ans);
    }
    return 0;
}

HDU 1338 Game Prediction 贪心

时间: 2024-12-21 13:00:04

HDU 1338 Game Prediction 贪心的相关文章

HDU 1338 Game Prediction【贪心】

解题思路: 给出 n  m 牌的号码是从1到n*m 你手里的牌的号码是1到n*m之间的任意n个数,每张牌都只有一张,问你至少赢多少次 可以转化为你最多输max次,那么至少赢n-max次 而最多输max次,则是对方最多赢max次,则用对方的最小的牌去依次比较你手中的牌(按照升序排),如果找到有比它小的,则对方赢一次 依次循环直到遍历完对方的牌. Game Prediction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536

【贪心专题】POJ 1323 &amp;&amp; HDU 1338 Game Prediction (贪心)

链接:click here~~ 题意: 有m个人,每个人有n张牌,牌点为在1~n*m中的不同的数.每回合每个人出一张牌,点数最大的那个人赢,给出A人初始时的n张牌的牌点,问A至少赢的次数. [解题思路] 看做两个人互相出牌,注意出牌的顺序,你有m张牌,我有m*(n-1)张牌,每次我都出比你大一点的牌,如果没有,出最小的m张牌(可以忽略), 每次出最大的.如果别人手中最大的小于你的.得分+1,而对方则选择最小的一个扔掉.如果对方最大的大于你手中最大的,对方会选择自己手中最小但是比你最大的大的牌丢掉

HDU 1338 Game Prediction

这题我用的是贪心算法,我的理解是这样的: 要求我最少能赢的次数,就是求别人最多能赢的次数.首先把我的牌先升序排序,然后我从小开始出,对于我出的牌,别人应该尽可能的压,而且用他们比我大的最小的那张牌:如果他们不压,那么他们后面这张牌就很有可能用不上,就少赢一次. #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<stack> #inc

hdu 4296 Buildings(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1822    Accepted Submission(s): 722 Problem Description Have you ever heard the sto

hdu 4864 Task (贪心)

# include <stdio.h> # include <algorithm> # include <string.h> using namespace std; struct node { int t; int v; int yy; }; struct node a[100010],b[100010]; bool cmp(node a1,node a2) { if(a1.t==a2.t)//先按时间从大到小 return a1.v>a2.v;//再按水平从大

HDU 5014 Number Sequence 贪心 2014 ACM/ICPC Asia Regional Xi&#39;an Online

尽可能凑2^x-1 #include <cstdio> #include <cstring> const int N = 100005; int a[N], p[N]; int init(int x) { int cnt = 0; while(x > 1) { x /= 2; cnt ++; } return cnt + 1; } int main() { int n; while(~scanf("%d", &n)){ for(int i = 0;

HDU 4903 (模拟+贪心)

Fighting the Landlords Problem Description Fighting the Landlords is a card game which has been a heat for years in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 1

HDU 1045 Fire Net 贪心

Problem Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle that has four openings through wh

hdu 1009 FatMouse&#39; Trade(贪心)

题目来源:hdu 1009 FatMouse' Trade FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 54581 Accepted Submission(s): 18299 Problem Description FatMouse prepared M pounds of cat food, ready