B. Qualifying Contest_排序
1 second
256 megabytes
standard input
standard output
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.
The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.
Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.
The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 10 000, n ≥ 2m) — the number of participants of the qualifying contest and the number of regions in Berland.
Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).
It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.
Print m lines. On the i-th line print the team of the i-th region — the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Sidorov Ivanov
Andreev Semenov
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
?
Andreev Semenov
解题报告:
1、题目很简单,就是要看清题意,主意输出哦!
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string> using namespace std; typedef long long LL; vector<pair<int,string> > v[]; int n,m; bool cmp(const pair<int,string>&a,const pair<int,string>&b)
{
if(a.first==b.first)
return a.second>b.second;
else return a.first>b.first;
} int main()
{ scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
v[i].clear(); for(int i=;i<=n;i++)
{
int id,score;
char name[];
scanf("%s%d%d",name,&id,&score);
v[id].push_back(make_pair(score,name));
} for(int i=;i<=m;i++)
sort(v[i].begin(),v[i].end(),cmp); for(int i=;i<=m;i++)
{
if(v[i][].first==v[i][].first)
{
if(v[i].size()==||v[i][].first>v[i][].first)
printf("%s %s\n",v[i][].second.c_str(),v[i][].second.c_str()); else puts("?");
continue;
}
if(v[i].size()==||v[i][].first>v[i][].first)
printf("%s %s\n",v[i][].second.c_str(),v[i][].second.c_str());
else puts("?"); }
return ;
}
B. Qualifying Contest_排序的更多相关文章
- Codeforces Round #346 (Div. 2) B Qualifying Contest
B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...
- Codeforces Round #346 (Div. 2) B. Qualifying Contest 水题
B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Be ...
- codeforces 659B B. Qualifying Contest(水题+sort)
题目链接: B. Qualifying Contest time limit per test 1 second memory limit per test 256 megabytes input s ...
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- iOS可视化动态绘制八种排序过程
前面几篇博客都是关于排序的,在之前陆陆续续发布的博客中,我们先后介绍了冒泡排序.选择排序.插入排序.希尔排序.堆排序.归并排序以及快速排序.俗话说的好,做事儿要善始善终,本篇博客就算是对之前那几篇博客 ...
- JavaScript实现常用的排序算法
▓▓▓▓▓▓ 大致介绍 由于最近要考试复习,所以学习js的时间少了 -_-||,考试完还会继续的努力学习,这次用原生的JavaScript实现以前学习的常用的排序算法,有冒泡排序.快速排序.直接插入排 ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- 算法与数据结构(十三) 冒泡排序、插入排序、希尔排序、选择排序(Swift3.0版)
本篇博客中的代码实现依然采用Swift3.0来实现.在前几篇博客连续的介绍了关于查找的相关内容, 大约包括线性数据结构的顺序查找.折半查找.插值查找.Fibonacci查找,还包括数结构的二叉排序树以 ...
- 算法与数据结构(七) AOV网的拓扑排序
今天博客的内容依然与图有关,今天博客的主题是关于拓扑排序的.拓扑排序是基于AOV网的,关于AOV网的概念,我想引用下方这句话来介绍: AOV网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...
随机推荐
- HIVE分析函数
ROWS BETWEEN含义,也叫做WINDOW子句: PRECEDING:往前 FOLLOWING:往后 CURRENT ROW:当前行 UNBOUNDED:起点,UNBOUNDED PRECEDI ...
- java不可见字符 trim
trim()的作用去掉前后的空格, 但是解析excel,出现一个字符串trim之后还是有”空格“ 做了一下实验,原来一些不可见的字符不一定是“空格”, trim()也去不掉, 只能自己写方法了
- python练习六十四:EXCEL文件处理
假设要读取number.txt文件中内容,code.txt文件内容如下 [ [1,2,3], [4,5,6], [7,8,9] ] 数据写入表格,如图 写文件(如果有文件,那直接调用就行,我这里自己先 ...
- python数据库的增删改查
#coding=utf- from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlal ...
- Error in event handler for "el.form.change": "TypeError: value.getTime is not a function"
首先说一下我使用的实际场景 html代码: js代码: 首先说明出现原因,elementUI的日期选择器[el-date-picker]在加上格式 value-format="yyyy-MM ...
- 转 深入解析:一主多备DG环境,failover的实现过程详解 以及 11g 容灾库可以在线添加tempfile. 以及 11g 容灾库可以在线添加logile.
https://yq.aliyun.com/articles/229600 核心,就是11g通过datafille_scn 号来追日志,而不是日志序列号来追日志. 加快standby switchov ...
- Mac 系统变量
vim .bash_profile ========================= MAVEN_HOME = < ... > export MAVEN_HOME =========== ...
- entity framework discriminator error
前几天使用code first碰到错误:列名 'Discriminator' 无效.这是一个很少见的错误,搜索了很久才发现是code first的poco实体对象的继承问题. 比如,我定义了一个实体类 ...
- 测试阿里云1核2g轻量级服务器的吞吐量
使用jmeter对部署的dbshop发起请求,单线程5000次请求 面板为宝塔界面 吞吐量大概在每秒48个请求左右.可以看出阿里云1核2g服务器其实并不能进行实战,只是新手练手而已. 阿里云另一种ec ...
- 工作采坑札记:3. Spark中es-hadoop插件异常解决
1. Es-Hadoop异常: org.elasticsearch.hadoop.EsHadoopException: Could not write all entries [615/300864] ...