问题 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 【排序】的更多相关文章

  1. upc组队赛5 Ingenious Lottery Tickets【排序】

    Ingenious Lottery Tickets 题目描述 Your friend Superstitious Stanley is always getting himself into trou ...

  2. Problem I: Ingenious Lottery Tickets

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

  3. CSU - 2055 Wells‘s Lottery

    Description As is known to all, Wells is impoverished. When God heard that, God decide to help the p ...

  4. 使用Extjs组件实现Top-Left-Main布局并且增加事件响应

    每次在毕业答辩会上,看到同专业的同学只要是XXX管理系统,就是下图所示的界面,看来这中布局还是很受欢迎的(偷笑).接下来进入我们正题,在web项目无论是前端还是后台管理比较常见的布局就是Top-Lef ...

  5. topcoder算法练习2

    Problem Statement      In most states, gamblers can choose from a wide variety of different lottery ...

  6. UVA10325 The Lottery(容斥原理)

    题意: 给n,m,和m个数(k1~km).求1~n中有多少个数不是(k1~km)中任意一数的倍数. 题解: 容斥模板题.反面考虑,a的倍数有n/a个:既是a,也是b的倍数,即lcm(a,b)的倍数有n ...

  7. UVA 10325 The Lottery( 容斥原理)

    The Sports Association of Bangladesh is in great problem with their latest lottery `Jodi laiga Jai'. ...

  8. php 彩票类 lottery

    <?php /* * For the full copyright and license information, please view the LICENSE * file that wa ...

  9. uva - The Lottery(容斥,好题)

    10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...

随机推荐

  1. mysql存储emoji问题

    前一段时间,项目中需要在数据库中存储emoji,由于编码格式不对,直接导致数据库报错,后来修改mysql的编码,就解决了 emoji符号实际上是文本,并不是图片,它们仅仅显示为图片 在mysql5.5 ...

  2. 16.vue-cli跨域,swiper,移动端项目

    ==解决跨域:== 1.后台 cors cnpm i -S cors 2.前端 jsonp 3.代理 webpack: myvue\config\index.js 找 proxyTable proxy ...

  3. 记一次GRPC使用报错排查

    项目一直使用grpc作为服务交互程序,其中我负责的java模块第一次引用该框架:当框架搭建好后,建立客户端代码,报错: Runable Error:java.lang.IllegalAccessErr ...

  4. php中,echo,print,var_dump的三个区别

    1.echo语句 echo - 能够输出一个以上的字符串 <?php      echo "<h2>www.dc3688.com</h2>";     ...

  5. str、tuple、dict之间的相互转换

    字符串.字典.元祖之间的相互转换: 1.字符串与列表之间的转换 str1 = 'ADMINphuang' '''str--->list''' list1=str1.split('p') prin ...

  6. SVN操作步骤

    1.第一次检出 svn co svn://192.168.1.1:5555/MMM 2.代码更新 svn update 3.代码提交 svn add *.c svn commit -m "d ...

  7. Python中time模块详解(转)

    在平常的代码中,我们常常需要与时间打交道.在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. 在开始之前,首先要说明这几点: ...

  8. F#周报2019年第4期

    新闻 F# 4.6预览 fuget.org现在显示包依赖从属,你曾经想要了解谁在使用你的类库吗?现在你可以知道了! F#被加入Wikipedia的流式接口页面 采访Erik Schierboom Az ...

  9. 实体框架—Entity Framework

    简称EF,是微软以ADO.NET为基础所发展出来的对象关系对应(ORM)解决方案. EF就是用来处理数据的,与数据库打交道.但是底层还是用到了ADO.NET的那一套东西. 为什么叫对象关系对应解决方案 ...

  10. DIOCP3-粘包处理

    DIOCP3-粘包处理   什么是粘包: 第一次发送  12345, 第二次发送abcde, 底层socket可能会一次性进行发送12345abcde,或者对方可能一次性进行了接收,那接收的时候,你可 ...