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 ...
随机推荐
- Codeforces Round 504
(交互题真神奇,,,我自己瞎写了一发目测样例都没过去就AC了...) (只出了两题的竟然没掉下蓝名真是可怕) A:我的代码太不美观了,放个同学的(因为我是c++63分的蒟蒻所以根本不知道那些函数怎么用 ...
- react-create-app
github地址 配置文档 环境变量 λ yarn add classnames lodash @material-ui/core react-router-dom mobx mobx-react r ...
- p1010幂次方---(分治)
题目描述 任何一个正整数都可以用222的幂次方表示.例如 137=27+23+20137=2^7+2^3+2^0 137=27+23+20 同时约定方次用括号来表示,即aba^bab 可表示为a(b) ...
- 通过Navicat远程连接MySQL
参考: http://blog.csdn.net/apple9005/article/details/53033148 问题一:在主机下通过Navicat连接服务器MySql的时候,提示“2003 C ...
- rocketMQ安装部署详细解析
近来研究了Apache开源项目rocketMQ(原为阿里项目),并在两台linux服务器上完成了部署,现在整理下,供大家参考学习. 一.简介rocketMQRocektMQ是阿里巴巴在2012年开源的 ...
- Fiddler_内置命令行_03
Fiddler左下角有一个命令框 [基础命令] [举例说明] ? 回车之后,匹配的内容如下图 stop [断点命令] FIddler断点功能就是将请求截获下来,但是不发送,这个时候你可以干很多事情, ...
- 10.9-uC/OS-III任务管理
1.OSTaskCreate () 要使用 uC/OS 的任务必须先声明任务控制块和创建任务,调用 OSTaskCreate () 函数可以创建一个任务. 2.OSTaskSuspend () OST ...
- mongodb删除重复数据
注:mongodb当前版本是3.4.3 插入六条数据: 查询存在重复的数据: 查询并循环删除重复数据: 删除语句解析: db.userInfo.aggregate([ { ...
- python基础(8)-装饰器函数&进阶
从小例子进入装饰器 统计一个函数执行耗时 原始版本 import time # time模块有提供时间相关函数 def do_something(): print("do_something ...
- [js]js设计模式-原型模式
构造函数模型- 对象的属性和方法每人一份 function createJs(name, age) { this.name = name; this.age = age; this.writeJs = ...