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 ...
随机推荐
- Python学习笔记006
算术运算符 加+ 减- 乘* 除/ 整除//,地板除 取余% 指数** ()区分 优先级 比较运算符 赋值 = 等于 == 不等于 != 大于等于 >= 小于等于 <=
- 树 插件 ztree 的基本用法
因业务需要 用到 ztree 插件 第一次用tree插件上手有点难度 官网 http://www.treejs.cn/v3/main.php#_zTreeInfo 第一步:初始化树,树的所有数据从后台 ...
- [mjpeg @ ...] unable to decode APP fields: Invalid data found when processing input
通过FFmpeg打开自己笔记本摄像头(HP Wide Vision HD Camera)操作时遇到如下错误: [mjpeg @ 0000029be7cbd000] unable to decode A ...
- Azure DNS-
先看什么是DNS,通常来讲,DNS是将域名解析成IP的服务,例如www.azure.cn对应的IP地址是139.217.8.104 使用域名访问有如下好处: 1. 好记,使用特定的字母组合,代替ip地 ...
- intelliJ IDEA 全屏键盘手
从MyEclipse到IntelliJ IDEA --让你脱键盘,全键盘操作 从MyEclipse转战到IntelliJ IDEA的经历 我一个朋友写了一篇"从Eclipse到Android ...
- uniGUI之uniPanel(20)
1]uniPanel常用设置: 2]多个uniPanel在一个uniPanel里显示 uniPanel常用设置: 2]多个uniPanel在一个uniPanel里显示 uniPanel0.Alignm ...
- Python - metaclass元类
参考 https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014319106919 ...
- 为什么maven没有.m2文件
该问题可能描述不清,建议你重新提问 为什么maven没有.m2文件 彼岸之恋°DD | 浏览 4793 次 问题未开放回答 2016-09-23 17:29 最佳答案 对于初学者在安装配置好maven ...
- smoj2806建筑物
题面 有R红色立方体,G绿色立方体和B蓝色立方体.每个立方体的边长是1.现在有一个N × N的木板,该板被划分成1×1个单元.现在要把所有的R+G+B个立方体都放在木板上.立方体必须放置在单元格内,单 ...
- Windows API 常用函数---转载
Windows API 常用函数 2014-10-15 14:21 xiashengwang 阅读(2105) 评论(0) 编辑 收藏 .Net中虽然类库很强的,但还是有些时候功能有限,掌握 ...