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 ...
随机推荐
- Set和Map集合的比较
HashSet:数据进行hashCode比较,然后进行equals方法比较,根据比较结果进行排序.如果要对对象进行排序,对象类要重写hashCode和equals方法.TreeSet:如果要对对象进 ...
- nodeJS - 定义全局变量
定义 : global.变量名=‘xxxx’; 取出 : global.变量名
- Navigation源码(一) move_base最全解析
一.概述 目测是全网最全的解析,花了几个小时通读并整理的,供大家参考学习. 概况的话可以看下古月居 https://www.guyuehome.com/270,其实它是翻译官方的,英语ok的可以去ro ...
- MyuCMS_V2.1漏洞分析
前言 在CNVD看到一个MyuCMS的一个任意文件删除漏洞.然后去搜了下这个CMS,发现官网公告显示在V2.2.3版本修复了CNVD提供的多处漏洞. 怀着好奇的心里,去CNVD搜了下这个CMS,结果发 ...
- ch8 基于浮动的布局(两列浮动布局、三列浮动布局)
CSS布局技术的根本是3个基本概念:定位.浮动.外边距操纵. 只需要设置希望定位的元素的宽度,然后将它们向左或向右浮动.因为浮动的元素不再占据文档流中的任何空间,它们就不再对包围他们的块框产生任何影响 ...
- DRF项目之层级关系
一共分为四层关系. 第一层:视图 用来接收前端传递的参数,并实现业务逻辑相关的数据处理,并将数据通过创建序列化器对象的形式传递给序列化器. 第二层:序列化器 接收前端传递的数据,并将数据进行序列化操作 ...
- 从零开始编写IntelliJ IDEA插件
写Java代码的时候,经常会涉及到重复性的操作,这个时候就会想要是有这样一个插件就好了,如果是大家都会遇到的场景,IDE或许已经提供了,再不然也有可能有人编写了相关的插件.要是这个操作是你们的编码环境 ...
- 让UITextField全选
[textField selectAll:self];
- 设计模式---JDK动态代理和CGLIB代理
Cglig代理设计模式 /*测试类*/ package cglibProxy; import org.junit.Test; public class TestCglib { @Test public ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮大小
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...