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': ' ');
}
}
}

最新文章

  1. 谈谈一些有趣的CSS题目(九)-- 巧妙的实现 CSS 斜线
  2. 穿越之旅之--android中如何执行java命令
  3. BeanDefinitionStoreException
  4. 【WP 8.1开发】推送通知测试服务端程序
  5. 中型企业的IT运维策略
  6. 转:c++类实例在内存中的分配
  7. NCBI原始数据下载by Aspera Connect
  8. 51nod1215 数组的宽度
  9. hp惠普服务器监控硬盘
  10. linux bugfree 安装
  11. [Android]获取设备相关信息
  12. ⑤JS返回格式化的当前时间和上周时间
  13. Java 8新特性探究(五)Base64详解
  14. react react-native 日期插件 m-date-picker / rmc-date-picker的使用
  15. Ubuntu 18.04搭建Git服务器
  16. Baltic Dry Index
  17. 利用Fiddler和Wireshark解密SSL加密流量
  18. pageadmin CMS网站建设教程:模板中如何实现信息数据共享
  19. Android 系统镜像: boot.img kernel.img ramdisk.img system.img userdata.img cache.img recovery.img
  20. 问答项目---账号密码异步校验后进行PHP校验

热门文章

  1. delphi 简单的发送字符串消息
  2. 函数体中return下面的代码不执行,但是需要预解析
  3. Oracle之子查询:Top-N问题
  4. WTSEnumerateSessions 枚举session信息
  5. matlab直接运行fig文件时报错
  6. c++后台开发面试常见知识点总结(六)算法手写
  7. C语句模拟多任务实例
  8. 【JavaWeb项目】一个众筹网站的开发(三)第一个网页
  9. boost库:事件处理
  10. python--闭包函数、装饰器