POJ1323 LA2521 HDU1338 ZOJ1362 Game Prediction贪心

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ1323 LA2521 HDU1338 ZOJ1362 Game Prediction贪心相关的知识,希望对你有一定的参考价值。

Game Prediction
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 12596 Accepted: 6053

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

Beijing 2002

问题链接POJ1323 LA2521 HDU1338 ZOJ1362 Game Prediction
问题简述:给定2个整数m和n,手中牌的号码是1到m*n之间的任意n个数,每张牌都只有一张,问你至少赢多少次?
问题分析:该问题用贪心法来解决,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* POJ1323 LA2521 HDU1338 ZOJ1362 Game Prediction */

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int M = 20, N = 50;
int a[N], vis[M * N + 1];

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

        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
            vis[a[i]] = 1;
        }

        int cnt = n;
        for (int i =0; i < n; i++)
            for (int j = a[i] + 1; j <= m * n; j++)
                if (vis[j] == 0) {
                    cnt--;
                    vis[j] = 1;
                    break;
                }

        printf("Case %d: %d\\n", ++caseno, cnt);
    }

    return 0;
}

以上是关于POJ1323 LA2521 HDU1338 ZOJ1362 Game Prediction贪心的主要内容,如果未能解决你的问题,请参考以下文章

HDU1416 POJ1078 UVA653 LA5507 GizilchDFS

POJ2033 LA3078 HDU1508 ZOJ2202 AlphacodeDFS+DP

POJ2142 LA3185 HDU1356 The Balance同余方程

POJ2092 LA3157 HDU1347 ZOJ2250 Grandpa is Famous排序

POJ2704 HDU1208 LA3390 Pascal‘s Travels递推+记忆化搜索

UVA619 LA5465 POJ1312 HDU1314 ZOJ1272 Numerically Speaking大数+进制