zoukankan      html  css  js  c++  java
  • POJ 1323 Game Prediction

    Game Prediction
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 8956   Accepted: 4269

    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
    题目大意:M个人,每人N张牌,每轮比较谁出的牌大,最大者为胜。现在给定M和N,以及你的牌,要求输出你至少能确保获得几轮的胜利。
    解题方法:先对所有的牌进行从大到小排序,每次出牌之前看比当前牌大的牌是否出完,如果出完则结果加一并把当前那张牌出完,如果没有出完则把没出的最大的那张和当前的牌出了。
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    
    bool cmd(const int &a, const int &b)
    {
        return a > b;
    }
    
    int main()
    {
        int visited[1005];
        int card[55];
        int m, n, ans, nCase = 0;
        bool flag = false;
        while(scanf("%d%d", &m, &n) != EOF && m != 0 && n != 0)
        {
            ans = 0;
            memset(visited, 0, sizeof(visited));
            for (int i = 0; i < n; i++)
            {
                scanf("%d", &card[i]);
            }
            sort(card, card + n, cmd);
            for (int i = 0; i < n; i++)
            {
                flag = true;
                //从后向前查找比当前牌大的牌是否出完
                for (int j = m * n; j > card[i]; j--)
                {
                    //找到没出的最大的那张,出牌
                    if (!visited[j])
                    {
                        flag = false;
                        visited[j] = 1;
                        break;
                    }
                }
                //当前的牌出了
                visited[card[i]] = 1;
                //如果比当前牌大的牌全部出完,结果加一
                if (flag)
                {
                    ans++;
                }
            }
            printf("Case %d: %d
    ", ++nCase, ans);
        }
        return 0;
    }
     
  • 相关阅读:
    PHP jquery结合HTML5鼠标拖选头像图片并上传
    HTML5 CSS3 SwitchButton 自定义Radio风格
    IE浏览器在虚拟机中无法正常显示字符
    jQuery在updatepanel中使用造成内存泄露
    bootstrap下拉列表重置联动
    bootstrap正则表达式验证手机 座机 邮箱
    bootstrap重置校验方法
    分页
    函数解一元二次方程
    集合
  • 原文地址:https://www.cnblogs.com/lzmfywz/p/3240713.html
Copyright © 2011-2022 走看看