zoukankan      html  css  js  c++  java
  • Problem I: Ingenious Lottery Tickets

    Problem I: Ingenious Lottery Tickets


    Your friend Superstitious Stanley is always getting himself into trouble. This time, in his Super Lotto Pick and Choose plan, he wants to get rich quick by choosing the right numbers to win the lottery. In this lottery, entries consist of six distinct integers from 1 to 49, which are written in increasing order. Stanley has compiled a list of winning entries from the last n days, and is going to use it to pick his winning numbers.
    In particular, Stanley will choose the six numbers that appeared the most often. When Stanley is breaking ties, he prefers smaller numbers, except that he prefers seven to every other number. What is Stanley’s entry?


    Input


    The first line of input contains a single integer T (1 ≤ T ≤ 100), the number of test cases. The first line of each test case contains a single integer n (1 ≤ n ≤ 1,000), the number of winning entries that Stanley compiled. The next n lines each contain a lottery entry as described above.


    Output


    For each test case, output a single line containing Stanley’s entry.
    Sample Input

    2

    3

    1 2 3 4 5 6

    4 5 6 7 8 9

    7 8 9 10 11 12

    3

    1 2 3 4 5 6

    4 5 6 7 8 9

    1 2 3 7 8 9

    Sample Output

    4 5 6 7 8 9

    1 2 3 4 5 7
    Explanation
    In the first test case, the numbers 4 through 9 appear twice each, while all other numbers appear at most one time.
    In the second test case, all numbers 1 through 9 appear twice each. The tiebreaking rule means Stanley prioritizes picking 7 and then the five smallest numbers.

    题意:选出出现次数最多的六位数字,按从小到大输出,如果次数相同,选数字较小的,如果第六位数字出现的次数和数字7出现的次数相同,就选7

    #include<iostream>
    #include<math.h>
    #include<algorithm>
    #include<map>
    #include<set>
    #define ll long long
    using namespace std;
    map<int,int>m;
    multiset<int>mm;
    struct node
    {
        int num;
        int cnt;
    }p[1005];
    bool cmp(node a,node b)
    {
        if(a.cnt!=b.cnt)
            return a.cnt>b.cnt;
        else
            return a.num<b.num;
    }
    int main()
    {
        int t,n,x;
        cin>>t;
        while(t--)
        {
            m.clear();
            mm.clear();
            cin>>n;
            int flag=0;
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<6;j++)
                {
                    cin>>x;
                    if(x==7)
                    {
                        flag++;
                        continue;
                    }
                    m[x]++;
                }
            }
            int k=0;
            map<int,int>::iterator it;
            for(it=m.begin();it!=m.end();it++)
            {
                p[k].num=(it->first);
                p[k].cnt=(it->second);
                k++;
            }
            sort(p,p+k,cmp);
            for(int i=0;i<k;i++)
            {
                if(mm.size()>=6)
                    break;
                else if(mm.size()==5)
                {
                    if(p[i].cnt>flag)
                        mm.insert(p[i].num);
                    else
                        mm.insert(7);
                }
                else
                    mm.insert(p[i].num);
                
            }
            
            multiset<int>::iterator itt;
            for(itt=mm.begin();itt!=mm.end();itt++)
            {
                if(itt==mm.begin())
                    cout<<*itt;
                else 
                    cout<<' '<<*itt;
            }
            cout<<endl;
    
        }
        return 0;
    }
  • 相关阅读:
    Ubuntu使用PBIS认证
    命令行运行Python脚本时传入参数的三种方式
    Python中调用shell
    Install chocolatey
    Configure vyatta
    Linux: Block Port With IPtables
    转:PHPStorm+XDebug进行调试图文教程
    转 Fira Code | 为写程序而生的字体
    转 [PHP]
    转:Drupal 如何得到字段的值?
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11281425.html
Copyright © 2011-2022 走看看