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[];
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=;
for(int i=;i<n;i++)
{
for(int j=;j<;j++)
{
cin>>x;
if(x==)
{
flag++;
continue;
}
m[x]++;
}
}
int k=;
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=;i<k;i++)
{
if(mm.size()>=)
break;
else if(mm.size()==)
{
if(p[i].cnt>flag)
mm.insert(p[i].num);
else
mm.insert();
}
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 ;
}

Problem I: Ingenious Lottery Tickets的更多相关文章

  1. Ingenious Lottery Tickets 【排序】

    问题 I: Ingenious Lottery Tickets 时间限制: 1 Sec  内存限制: 128 MB 提交: 590  解决: 135 [提交] [状态] [命题人:admin] 题目描 ...

  2. upc组队赛5 Ingenious Lottery Tickets【排序】

    Ingenious Lottery Tickets 题目描述 Your friend Superstitious Stanley is always getting himself into trou ...

  3. UVA10325 The Lottery(容斥原理)

    题意: 给n,m,和m个数(k1~km).求1~n中有多少个数不是(k1~km)中任意一数的倍数. 题解: 容斥模板题.反面考虑,a的倍数有n/a个:既是a,也是b的倍数,即lcm(a,b)的倍数有n ...

  4. UVA 10325 The Lottery( 容斥原理)

    The Sports Association of Bangladesh is in great problem with their latest lottery `Jodi laiga Jai'. ...

  5. uva - The Lottery(容斥,好题)

    10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...

  6. CSU - 2055 Wells‘s Lottery

    Description As is known to all, Wells is impoverished. When God heard that, God decide to help the p ...

  7. poj 2828 Buy Tickets (线段树(排队插入后输出序列))

    http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissio ...

  8. topcoder算法练习2

    Problem Statement      In most states, gamblers can choose from a wide variety of different lottery ...

  9. 使用Extjs组件实现Top-Left-Main布局并且增加事件响应

    每次在毕业答辩会上,看到同专业的同学只要是XXX管理系统,就是下图所示的界面,看来这中布局还是很受欢迎的(偷笑).接下来进入我们正题,在web项目无论是前端还是后台管理比较常见的布局就是Top-Lef ...

随机推荐

  1. java获取指定月份有几个星期x,获取指定月份跨了多少个星期

    例如获取2020年5月一共有多少个星期二,一共跨了多少个星期 public class MainTest { public static void main(String[] args) throws ...

  2. ApacheDbUtilsTest

    ApacheDbUtilsTest package p1; import com.DataSourceUtil; import entity.Student; import org.apache.co ...

  3. 搭建私有CA并实现证书颁发

    一.搭建私有CA服务器 1.安装包 # yum -y install openssl 2.生成密钥对儿 # cd /etc/pki/CA # (umask 077;openssl genrsa -ou ...

  4. eclipse启动时权限不够的问题

    eclipse启动时权限不够的问题 2009年04月28日 19:19:00 tomey21 阅读数 1445   安装好后每次都要用root权限运行,比较郁闷,摸索了一下,修改一下相关目录的权限就可 ...

  5. Ubuntu下安装GTK的三种方法

    我利用此方法成功在UBUNTU 10.04下安装GTK 2.20.1. 一.安装 1.安装gcc/g++/gdb/make 等基本编程工具 $sudo apt-get install build-es ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表单:选择框(Select)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. java并发:interrupt进程终止

    interrupt进程终止 interrupt()源码 /** * Interrupts this thread. * * <p> Unless the current thread is ...

  8. Python【day 19】反射

    '''''' ''' 一.昨日内容回顾 1.依赖关系 1.弱关系.多态 1.松耦合 2.大象可以装冰箱,也可以装高压锅,就是多态 2.例子: 1.大象装冰箱 2.大象装高压锅 3.你打车 3.写法 大 ...

  9. Day3-R-Aggressive cows POJ2456

    Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are locat ...

  10. 基于PIL模块创建验证码图片

    def get_valid_img(request): # 方式2:基于PIL模块创建验证码图片 from PIL import Image, ImageDraw, ImageFont from io ...