问题 I: Ingenious Lottery Tickets
时间限制: 1 Sec 内存限制: 128 MB
提交: 593 解决: 136
[提交] [状态] [命题人:admin]
题目描述
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?
输入
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.
输出
For each test case, output a single line containing Stanley’s entry.
样例输入
复制样例数据
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
样例输出
4 5 6 7 8 9
1 2 3 4 5 7
提示
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.
结构体排序,这个题是真的坑
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std;
set<int>se;
struct node
{
int id;
int num;
};
node arr[10005];
bool com(node a,node b )
{
if(a.num==b.num)
return a.id<b.id;
else
return a.num>b.num;
}
int main()
{
int t;
cin >>t;
while (t--)
{
memset(arr,0,sizeof(arr));
int n;
int cnt=0;
cin >>n;
for(int i=0; i<6*n; i++)
{
int a;
cin >>a;
if(se.count(a)==0)
{
cnt++;
se.insert(a);
}
arr[a].id=a;
arr[a].num++;
}
sort(arr,arr+50,com);
int flag=0;
for(int i=0; i<cnt-1; i++)
{
if(arr[i].num!=arr[i+1].num)
{
flag=1;
break;
}
}
if(flag)
{
int c[10];
int cnt=0;
for(int i=0; i<=5; i++)
{
c[cnt++]=arr[i].id;
}
sort(c,c+6);
for(int i=0;i<=5;i++){
cout<<c[i]<<" ";
}
cout<<endl;
}
else
{
int c[8];
int ans=0;
int f=0;
for(int i=0; i<cnt; i++)
{
if(arr[i].id==7)
{
f=1;
break;
}
}
if(f==1)
{
c[5]=7;
int cnt1=0;
for(int i=0; i<5; i++)
{
c[cnt1++]=arr[i].id;
}
sort(c,c+6);
for(int i=0; i<6; i++)
{
cout<<c[i]<<" ";
}
cout<<endl;
}
else
{
int cnt2=0;
for(int i=0; i<6; i++)
{
c[cnt2++]=arr[i].id;
}
sort(c,c+6);
for(int i=0; i<6; i++)
{
cout<<c[i]<<" ";
}
cout<<endl;
}
}
se.clear();
}
return 0;
}