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 ...
随机推荐
- TemplateBuilder Android Studio
TemplateBuilder:是Android Studio的一个开发模板,大大提高开发效率.
- Nestjs 序列化(Serialization)
文档 在发送实际响应之前,Serializers为数据操作提供了干净的抽象层.例如,应始终从最终响应中排除敏感数据(如用户密码) λ yarn add class-transformer cats.e ...
- wamp 进入到项目中找不到localhost
重点在 www 目录的 index.php 里面,把里面没有第一句没有被注释的话: $suppress_localhost = true; 改成 $suppress_localhost = false ...
- dedecms (织梦)漏洞&exp整理
[通杀]dedecms plussearch.php 注入漏洞利用方式看结果如果提示Safe Alert: Request Error step 2 !那么直接用下面的exp查看源代码打印帮助1 /p ...
- linux中的cd
cd命令 实例 hling@hling:~$ cd /home/hling/桌面/huanghling@hling:~/桌面/huang$ cd ..hling@hling:~/桌面$ cd ..hl ...
- A股时间窗口
春节躁动行情:大消费,文娱影视 一号文件:泛农业股 两会行情:两会概念 糖酒会:白酒,糖业 五穷六绝:半年节点,[市场缺钱] 暑期档:文娱影视 国庆行情:军工,文娱影视 年底:阳历年底,[市场缺钱] ...
- rebuild online时意外中断 再次重建时报错解决方法
rebuild online时意外中断 再次重建时报错 SQL> alter index PARTY.IDX_CM_INDIV_CUSTOMER_4 rebuild online; alter ...
- GIS常用知识列举
GIS知识分类 我认为GIS知识,大体可分为以下三类. G——测量学.地图学.误差理论等基础——测绘方面 I——数据库.开发——IS方面 S——GIS原理——结合前面两种知识的理念 第一类,是基础,有 ...
- mysql脚本手动修改成oracle脚本
今天有一个需求,立了一个新项目,新项目初步定了使用了现有的框架,但数据库要求由原来的mysql改成oracle,所以原来的基础版本的数据库脚本就需要修改成符合oracle的脚本,修改完成后,总结了一下 ...
- C#基础加强(8)之委托和事件
委托 简介 委托是一种可以声明出指向方法的变量的数据类型. 声明委托的方式 格式: delegate <返回值类型> 委托类型名(参数) ,例如: delegate void MyDel( ...