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 ...
随机推荐
- jsp页面展示更加商品的分类,控制商品的显示
我的大概思路是这样的,第一后果获取所有的商品分类 保存在list集合里面,第二从后台获取所有的商品 第三在JSP页面遍历商品分类集合放在页面的左边,然后jsp页面商品详细信息这块,也得先遍历商品分类, ...
- Controller层注解
/** * Copyright © 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite< ...
- scrapy shell中遇到的坑
如果直接scrapy shell +网址 然后发现返回200 但是request和response的网址不同,那么可以使用百度短网址 https://dwz.cn/ 进行缩短.这样一般就能解决问题
- 图解jvm--(三)类加载与字节码技术
类加载与字节码技术 1.类文件结构 根据 JVM 规范,类文件结构如下 ClassFile { u4 magic; //魔数 u2 minor_version; //小版本号 u2 major_ver ...
- 洛谷 P6046 [CTSC2000]快乐的蜜月
先讲解一下如何处理这道题的毒瘤输入.\(m\) 和 \(d\) 之间的"/"和" TO "都可以用 getchar() 强行吃掉,日期的转换可以用公式 \(s_ ...
- JS中的原始类型和判断方法
ECMAScript 中定义了 7 种原始类型: Boolean String Number Null Undefined Symbol(新定义) BigInt(新定义) 注意: 原始类型不包含 Ob ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:"text-warning" 类的文本样式
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- layer 点击yes后在回调函数里获取layer.open({})iframe里面元素
参考:http://fly.layui.com/jie/19690/ yes: function(index, layero) { uid.value = $(layero).find('iframe ...
- Python3中找不到xrange定义和不能用len(map())
问题1:python3中找不到xrange的定义,vscode中提示未定义 解决:改成range,因为python3中取消了vscode 问题2:python3中map函数返回的是迭代器,因此无法用l ...
- SystemVerilog基本语法总结(中)
Systemverilog 语法总结(中) 上一个博客分享了SV基本的概念,这一博客继续分享,等下一个博客分享一个公司的验证的笔试题目. l 事件 背景: Verilog中当一个线程在一个事件上发生阻 ...