codeforces659B
Qualifying Contest
Very soon Berland will hold a School Team Programming Olympiad. From each of the mBerland 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.
Input
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 1 to 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.
Output
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.
Examples
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
Note
In the first sample region teams are uniquely determined.
In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
sol:STL非常好用,按照分数从大到小排序后如果第二名分数和第三名相同就无法确定了
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=,B=;
int n,m;
struct Record
{
char Name[B];
int Score;
};
inline bool cmp(Record p,Record q)
{
return p.Score>q.Score;
}
vector<Record>Vec[N];
char Name[B];
int main()
{
int i;
R(n); R(m);
for(i=;i<=n;i++)
{
Record tmp;
int id;
scanf("%s",tmp.Name);
R(id);
R(tmp.Score);
Vec[id].push_back(tmp);
}
for(i=;i<=m;i++)
{
sort(Vec[i].begin(),Vec[i].end(),cmp);
if(Vec[i].size()==)
{
puts("?");
}
else if(Vec[i].size()==)
{
printf("%s",Vec[i][].Name);
putchar(' ');
printf("%s",Vec[i][].Name);
putchar('\n');
}
else
{
if(Vec[i][].Score==Vec[i][].Score) puts("?");
else
{
printf("%s",Vec[i][].Name);
putchar(' ');
printf("%s",Vec[i][].Name);
putchar('\n');
}
}
}
return ;
}
/*
input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
output
Sidorov Ivanov
Andreev Semenov input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
output
?
Andreev Semenov
*/
codeforces659B的更多相关文章
随机推荐
- Hyper-V 安装系统
注: 如屏幕前的您没有一定的网络知识(可能会使你的网络造成错乱),请勿按该文档操作. // 注:如果开启了Hyper-V,再使用VMware时在VMware上会报错,需把这里关闭后重启实体机后再开启V ...
- AI 机器学习基础
深度学习是机器学习的一个特定分支. 1.学习算法 对于某类任务T和性能度量P, 2.线性回归 3.正规方程(normal equation) 4.监督学习(supervised learning) 5 ...
- ImageView android:scaleType="centerCrop"
转载地址:http://www.cnblogs.com/yejiurui/archive/2013/02/25/2931767.html 在网上查了好多资料,大致都雷同,大家都是互相抄袭的,看着很费劲 ...
- SkylineGlobe6.5版本,在矿山、石油、天然气等能源行业的最新应用DEMO演示
SkylineGlobe6.5版本,在矿山.石油.天然气等能源行业的最新应用DEMO演示: http://v.youku.com/v_show/id_XNTc3Njc1OTEy.html 一个Pres ...
- ajax返回json时,js获取类型,是字符串类型
ajax向php服务端请求,并返回json串给前端. js发现得到的返回值的类型是字符串,不能直接取json对象属性,需要JSON.parse(). 怎么解决呢? 这需要在php返回json时,加上一 ...
- Ionic App之国际化(1)单个参数的处理
最近的app开发中需要考虑多语言国际化的问题,经查资料,目前大部分使用的是angular-translate.js这个组件,网站说明是这个:https://angular-translate.gith ...
- LeetCode Pow(x, n) (快速幂)
题意 Implement pow(x, n). 求X的N次方. 解法 用正常的办法来做是会超时的,因为可能有21亿次方的情况,所以需要优化一下.这里用到了快速幂算法,简单来说就是将指数分解成二进制的形 ...
- 【下一代核心技术DevOps】:(六)Rancher集中存储及相关应用
1. 前言 为什么要使用集中存储? 使用集中存储有个很大的优势是数据安全和统一管理,和集群完美配合. 产品集成存储经历过几个阶段: 1.单机本机存储. 系统使用本地硬盘存储 2.单网络集中存储. 局域 ...
- 天气提醒邮件服务器(python + scrapy + yagmail)
天气提醒邮件服务器(python + scrapy + yagmail) 项目地址: https://gitee.com/jerry323/weatherReporter 前段时间因为xxx上班有时候 ...
- Microsoft Visual Studio2013安装及单元测试
和大家分享一下我安装VS2013和单元测试的过程.VS是微软多种编程软件的集合,功能与工作环境更全面,相比VC++6.0来说是一个很大的提升. VS安装: VS的安装和普通软件相同,只是花费的时间很长 ...