Ingenious Lottery Tickets 【排序】
问题 I: Ingenious Lottery Tickets
时间限制: 1 Sec 内存限制: 128 MB
提交: 590 解决: 135
[提交] [状态] [命题人:admin]
题目描述
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': ' ');
}
}
}
Ingenious Lottery Tickets 【排序】的更多相关文章
- upc组队赛5 Ingenious Lottery Tickets【排序】
Ingenious Lottery Tickets 题目描述 Your friend Superstitious Stanley is always getting himself into trou ...
- Problem I: Ingenious Lottery Tickets
Problem I: Ingenious Lottery Tickets Your friend Superstitious Stanley is always getting himself int ...
- CSU - 2055 Wells‘s Lottery
Description As is known to all, Wells is impoverished. When God heard that, God decide to help the p ...
- 使用Extjs组件实现Top-Left-Main布局并且增加事件响应
每次在毕业答辩会上,看到同专业的同学只要是XXX管理系统,就是下图所示的界面,看来这中布局还是很受欢迎的(偷笑).接下来进入我们正题,在web项目无论是前端还是后台管理比较常见的布局就是Top-Lef ...
- topcoder算法练习2
Problem Statement In most states, gamblers can choose from a wide variety of different lottery ...
- 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'. ...
- php 彩票类 lottery
<?php /* * For the full copyright and license information, please view the LICENSE * file that wa ...
- uva - The Lottery(容斥,好题)
10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...
随机推荐
- J - Network of Schools
来源poj1236 A number of schools are connected to a computer network. Agreements have been developed am ...
- python 接口自动化测试二(request.get)
环境搭建好后,接下来我们先来了解一下requests的一些简单使用,主要包括: requests常用请求方法使用,包括:get,post requests库中的Session.Cookie的使用 其它 ...
- 【Java线程安全】 — ThreadLocal
[用法] 首先明确,ThreadLocal是用空间换时间来解决线程安全问题的,方法是各个线程拥有自己的变量副本. 既然如此,那么是涉及线程安全,必然有一个共享变量,我给大家声明一个: public c ...
- python语法_input
input:与用户的交互,返回用户输入的值 注意:input接受的所有数据都为字符串,即便输入的为数字,依然会被当成字符串
- 谁考了第k名
题目描述: 在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩. 输入: 第一行有两个整数,分别是学生的人数n(1≤n≤100),和求第k名学生的k(1≤k ...
- sql数据库光标变成黑快怎么回事?
可能是因为你按到了insert键啦,你再按一下insert键应该就可以啦. 光标变成块状说明当前是覆盖模式.光标变成竖条状说明当前是插入模式.
- Gym 101873C - Joyride - [最短路变形][优先队列优化Dijkstra]
题目链接:http://codeforces.com/gym/101873/problem/C 题意: 这是七月的又一个阳光灿烂的日子,你决定和你的小女儿一起度过快乐的一天.因为她真的很喜欢隔壁镇上的 ...
- 如何将本地大文件通过终端上传到linux服务器
第一种方式: SecureCRT下 上传文件只需在shell终端仿真器中输入命令“rz”,即可从弹出的对话框中选择本地磁盘上的文件,利用Zmodem上传到服务器当前路径下. 下载文件只需在s ...
- python基础(15)-socket网络编程&socketserver
socket 参数及方法说明 初始化参数 sk = socket.socket(参数1,参数2,参数3) 参数1:地址簇 socket.AF_INET IPv4(默认) socket.AF_INET6 ...
- Kafka实践1--Producer
一.Kafka设计原理参考: http://blog.csdn.net/suifeng3051/article/details/48053965?locationNum=2 http://www.cn ...