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. shell脚本中执行shell脚本

    1.a.sh #!/bin/sh name="hello" ./b.sh $name  2.b.sh(这里把b.sh与a.sh放在同一目录下,便于演示) #!/bin/sh ech ...

  2. 调用百度汇率api 获取各国的汇率值

    设置一个定时任务,每天更新汇率java代码如下 package com.thinkgem.jeesite.modules.huiLvApi.service; import java.io.Buffer ...

  3. 由Nginx反向代理引出的JCaptcha验证码验证失败的问题

    搜索关键字: 1)Windows本地开发正常,部署到Linux远程服务器上JCaptcha验证失败 2)Linux远程服务器上JCpatcha验证失败 3)Nginx反向代理后JCaptcha验证失败 ...

  4. 一文解读CAP (转)

    分布式系统(distributed system)正变得越来越重要,大型网站几乎都是分布式的. 分布式系统的最大难点,就是各个节点的状态如何同步.CAP 定理是这方面的基本定理,也是理解分布式系统的起 ...

  5. 论文写作+gnuplot制图

    一:论文写作 论文写作推荐使用LATEX+TEXStudio+TEXLive 1.CTeX官方网站:http://www.ctex.org/HomePage ,他类似于python环境 2.TeXst ...

  6. Day1学习总结

    # 1.print()# 2.input()# 3.if:# elif# else#4.while循环#5.for i in range()#6.break.continue#7.import ran ...

  7. Metric类型

    Metric类型 在上一小节中我们带领读者了解了Prometheus的底层数据模型,在Prometheus的存储实现上所有的监控样本都是以time-series的形式保存在Prometheus内存的T ...

  8. 白底黑字!Android浅色状态栏黑色字体模式(另)

    小彬什么都想做任重致远 关注 2016.06.30 10:16* 字数 489 阅读 3234评论 3喜欢 12 前言 由于该死不死的设计湿,设计了一套白色状态栏的UI.当然在iOS上可以实现自适应, ...

  9. oracle随机生成时间

    Julian Date定义 Julian Date:有效的日期范围是从公元前4713年1月1日到公元9999年12月31日.儒略日(julian date)是自公元前4713年1月1日中午12时起经过 ...

  10. lambda表达式和for_each,find_if

    1 lambda表达式可以允许我传递任意可调用对象,必须要有捕获列表和函数体,标准形式是[捕获列表] (参数列表)->return tpye{函数体} 谓词:一元谓词指的是只能接受一个传入参数, ...