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?

输入

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.

输出

For each test case, output a single line containing Stanley’s entry.

样例输入

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

样例输出

4 5 6 7 8 9
1 2 3 4 5 7

提示

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.

题意+题解

一共有 M * 6个数字 ,让你输出频率最高的那6个,其中7是幸运数字,如果频率相同的情况下一定会优先选择7

输出的时候要求从小到大输出,所以我们需要做两次排序,先按出现次数从大到小和幸运7规则 排出前6个数,再对这6个数进行从小到大排序

代码

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef pair<int,int> P;
typedef long long ll;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn = 10010;
int T;
int n,m;
struct node {
int cnt;
int id;
bool operator< (node b) const {
if(cnt == b.cnt) {
return id == 7 ? 1 : id < b.id; //如果频率相同优先选择7 再数字小的优先
}
return cnt > b.cnt; // 出现频率高的排在前面
}
}num[10005];
int op[10]; //选出6个数
int x;
int main(){
read(T);
while(T--){
int imax = -1;
read(m);
memset(num,0,sizeof(num));
while(m--){
for(int i = 0; i < 6;i++){
read(x);
num[x].id = x;
num[x].cnt ++;
imax = max(imax,x);
}
}
sort(num,num + imax + 1); //第一次排序,按照出现次数和幸运7规则
int tot = 0;
while(tot < 6){ ////选择前6个数字
op[tot] = num[tot].id;
tot++;
}
sort(op,op+tot);// 第二次排序,从小到大输出
for(int i = 0; i < 6; i++){
printf("%d%c",op[i],i == 5 ? '\n': ' ');
}
}
}

upc组队赛5 Ingenious Lottery Tickets【排序】的更多相关文章

  1. Ingenious Lottery Tickets 【排序】

    问题 I: Ingenious Lottery Tickets 时间限制: 1 Sec  内存限制: 128 MB 提交: 590  解决: 135 [提交] [状态] [命题人:admin] 题目描 ...

  2. Problem I: Ingenious Lottery Tickets

    Problem I: Ingenious Lottery Tickets Your friend Superstitious Stanley is always getting himself int ...

  3. upc组队赛14 Evolution Game【dp】

    Evolution Game 题目描述 In the fantasy world of ICPC there are magical beasts. As they grow, these beast ...

  4. upc组队赛5 Assembly Required【思维】

    Assembly Required 题目描述 Princess Lucy broke her old reading lamp, and needs a new one. The castle ord ...

  5. upc组队赛3 Chaarshanbegaan at Cafebazaar

    Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...

  6. upc组队赛1 过分的谜题【找规律】

    过分的谜题 题目描述 2060年是云南中医学院的百年校庆,于是学生会的同学们搞了一个连续猜谜活动:共有10个谜题,现在告诉所有人第一个谜题,每个谜题的答案就是下一个谜题的线索....成功破解最后一个谜 ...

  7. upc组队赛1 不存在的泳池【GCD】

    不存在的泳池 题目描述 小w是云南中医学院的同学,有一天他看到了学校的百度百科介绍: 截止到2014年5月,云南中医学院图书馆纸本藏书74.8457万册,纸质期刊388种,馆藏线装古籍图书1.8万册, ...

  8. upc组队赛1 黑暗意志【stl-map】

    黑暗意志 题目描述 在数千年前潘达利亚从卡利姆多分离之时,迷雾笼罩着这块新形成的大陆,使它不被外来者发现.迷雾同样遮蔽着这片大陆古老邪恶的要塞--雷神的雷电王座.在雷神统治时期,他的要塞就是雷电之王力 ...

  9. upc组队赛1 闪闪发光 【优先队列】

    闪闪发光 题目描述 一所位于云南昆明的中医药本科院校--云南中医学院. 因为报考某专业的人数骤减,正面临着停招的危机. 其中有九名少女想到一条妙计--成为偶像, 只要她们成为偶像,学校的名气便会增加, ...

随机推荐

  1. 非常全的Linux基础知识点

    Linux是每个后端程序员必须要掌握的系统,今天小编就给你分享一篇Linux基础知识点大全,看看你知道多少? 一. 从认识操作系统开始 1.1 操作系统简介 我通过以下四点介绍什么操作系统: 操作系统 ...

  2. 浅析java设计模式(一)----异构容器,可以存储任何对象类型为其他类提供该对象

    最近在着手重构一个java UI桌面项目,发现这个项目在一开始的时候由于需求不明确,以及开发人员对swing框架不熟悉等问题造成了页面代码混乱的情况:为了能够在各个类里都可以拿到其他类的引用去进行相应 ...

  3. 大众点评Java开发实时应用监控平台-CAT

    CAT介绍 CAT是基于Java开发的实时应用监控平台,包括实时应用监控,业务监控. CAT作为大众点评网基础监控组件,它已经在中间件框架(MVC框架,RPC框架,数据库框架,缓存框架等)中得到广泛应 ...

  4. SpringMVC学习(5):数据绑定2 @PathVariable、@CookieValue、@RequestHeader、@ModelAttribute..

    在系列(4)中我们介绍了如何用@RequestParam来绑定数据,下面我们来看一下其它几个数据绑定注解的使用方法. 1.@PathVariable 用来绑定URL模板变量值,这个我们已经在系列(3) ...

  5. 支持跨域的html元素

    image javascript iframe link

  6. linux随笔-05

    shell脚本&定时任务 编写Shell脚本 可以将Shell终端解释器当作人与计算机硬件之间的“翻译官”. Shell脚本命令的工作方式有两种:交互式和批处理. 交互式(Interactiv ...

  7. JDBC、ibatis(mybatis)、Hibernate有什么不同?

    ①JDBC编程流程固定,同时将sql语句和java代码混在了一起,经常需要拼凑sql语句,细节很繁琐: ②ibatis(mybatis)它不完全是一个ORM框架,因为MyBatis需要程序员自己编写S ...

  8. vue中Template 制作模版

    一.直接写在选项里的模板 直接在构造器里的template选项后边编写.这种写法比较直观,但是如果模板html代码太多,不建议这么写. javascript代码: var app=new Vue({ ...

  9. PHP+Redis 有序集合实现 24 小时排行榜实时更新

    基本介绍 Redis 有序集合和集合一样也是 string 类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个 double 类型的分数.redis 正是通过分数来为集合中的成员进行从 ...

  10. linux make: *** No targets specified and no makefile found. Stop.

    [root@localhost Python-]# ./configure checking build system type... x86_64-unknown-linux-gnu checkin ...