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[];
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的更多相关文章
- Ingenious Lottery Tickets 【排序】
问题 I: Ingenious Lottery Tickets 时间限制: 1 Sec 内存限制: 128 MB 提交: 590 解决: 135 [提交] [状态] [命题人:admin] 题目描 ...
- upc组队赛5 Ingenious Lottery Tickets【排序】
Ingenious Lottery Tickets 题目描述 Your friend Superstitious Stanley is always getting himself into trou ...
- UVA10325 The Lottery(容斥原理)
题意: 给n,m,和m个数(k1~km).求1~n中有多少个数不是(k1~km)中任意一数的倍数. 题解: 容斥模板题.反面考虑,a的倍数有n/a个:既是a,也是b的倍数,即lcm(a,b)的倍数有n ...
- UVA 10325 The Lottery( 容斥原理)
The Sports Association of Bangladesh is in great problem with their latest lottery `Jodi laiga Jai'. ...
- uva - The Lottery(容斥,好题)
10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...
- CSU - 2055 Wells‘s Lottery
Description As is known to all, Wells is impoverished. When God heard that, God decide to help the p ...
- poj 2828 Buy Tickets (线段树(排队插入后输出序列))
http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissio ...
- topcoder算法练习2
Problem Statement In most states, gamblers can choose from a wide variety of different lottery ...
- 使用Extjs组件实现Top-Left-Main布局并且增加事件响应
每次在毕业答辩会上,看到同专业的同学只要是XXX管理系统,就是下图所示的界面,看来这中布局还是很受欢迎的(偷笑).接下来进入我们正题,在web项目无论是前端还是后台管理比较常见的布局就是Top-Lef ...
随机推荐
- luogu P2704 炮兵阵地(经典状态压缩DP)
方格有m*n个格子,一共有2^(m+n)种排列,很显然不能使用暴力法,因而选用动态规划求解. 求解DP问题一般有3步,即定义出一个状态 求出状态转移方程 再用算法实现.多数DP题难youguan点在于 ...
- Python学习笔记009
不换行 print("Hello,world!",end='')print("Hello,world!",end='')print("Hello,wo ...
- C#的 IComparable 和 IComparer接口及ComparableTo方法的 区别(非常重要)
(1)https://blog.csdn.net/ios99999/article/details/77800819 C# IComparable 和 IComparer 区别 (2)https:// ...
- 6(计算机网络) 交换机与VLAN
拓扑结构是怎么形成的? 我们常见到的办公室大多是一排排的桌子,每个桌子都有网口,一排十几个座位就有十几个网口,一个楼层就会有几十个甚至上百个网口.如果算上所有楼层,这个场景自然比你宿舍里的复杂多了.具 ...
- linux kill命令以及 信号
kill命令介绍 命令作用 终止一个进程 语法: kill [-s signal|-p] [-q sigval] [-a] [--] pid... kill -l [signal] 选项 -l 信号, ...
- 「国家集训队」小Z的袜子
「国家集训队」小Z的袜子 传送门 莫队板子题. 注意计算答案的时候,由于分子分母都要除以2,所以可以直接约掉,这样在开桶算的时候也方便一些. 参考代码: #include <algorithm& ...
- 大部分政府网站U-mail存在直接拿shell漏洞
大部分网站政府网站U-mail存在直接拿shell漏洞加入webmail/userapply.php?execadd=333&DomainID=111直接爆出物理地址 然后将 aa' unio ...
- jqGrid 复选框实现单选
参考:https://blog.csdn.net/java0311/article/details/45575517
- kafka在zookeeper默认使用/为根目录,将/更换为/kafka
需求:kafka在zookeeper默认使用/为根目录,将/更换为/kafka 步骤:1.进入kafka的根目录: [root@node01 kafka_2.11-1.0.0]# cd /export ...
- status 后面的P和I是什么单词的缩写
我不是很肯定,有大概印象:P 为 performed, 已完成I 为 incomplete 未完成