hdu 1338Game Prediction

Game Prediction

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 717    Accepted Submission(s): 385

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)

通过已给出的数组 a  找出其余所有人的卡牌存放在一个数组 b 中

通过求 b 能赢得最多场max来间接求出 a 能赢得最少场ans

ans=n-max

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int a[55],b[1005];
    int i,j,ans,k,l;
    int n,m,t=0;
    while(cin>>n>>m,m&&n)
    {
        t++;
        memset(b,0,sizeof(b));
        for(i=0;i<m;i++)
            cin>>a[i];
        sort(a,a+m,cmp);
        /*for(i=0;i<m;i++)
        cout<<a[i];*/
        l=0;
        ans=0;
        for(i=m*n;i>a[m-1];i--)
        {   k=0;
            for(j=0;j<m;j++)
             {
                if(a[j]==i)
                   {
                        k=1;
                    continue;
                   }
             }
             if(!k)
             {b[l]=i;/*cout<<b[l]<<" ";*/l++;}
        }
        k=m*(n-1);
        j=0;
        for(i=0;i<m;i++)
           {
              if(a[i]<b[j])
              {
                  ans++;
                  j++;
              }
           }
           cout<<"Case "<<t<<": ";
        cout<<(m-ans)<<endl;
    }

    return 0;
}

hdu 1338Game Prediction

时间: 2024-10-27 11:19:28

hdu 1338Game Prediction的相关文章

HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B)

题目链接  2016 CCPC东北地区大学生程序设计竞赛 B题 题意  给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这些点以及这些点的所有祖先. 只有标号在树中真正被选上的点代表的这些原图中的边是存在的,这样就构成了一个新的图.求这个图的连通块个数. dfs整棵树,记$f[x]$为若$x$以及$x$的所有祖先被选上,那么构成的新的图的并查集) 这个实现比较简单,搜索的时候打上标记,回来的时候撤销即可. 这样预处理的

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. Du

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——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include

hdu 1207 汉诺塔II (DP+递推)

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往