码迷,mamicode.com
首页 > 其他好文 > 详细

Problem I: Ingenious Lottery Tickets

时间:2019-08-01 11:44:13      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:amp   pil   win   break   trouble   other   targe   clear   nsis   

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 ?rst line of input contains a single integer T (1 ≤ T ≤ 100), the number of test cases. The ?rst 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 ?rst 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 ?ve 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;
}

 

Problem I: Ingenious Lottery Tickets

标签:amp   pil   win   break   trouble   other   targe   clear   nsis   

原文地址:https://www.cnblogs.com/-citywall123/p/11281425.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!