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的更多相关文章
随机推荐
- 分布式计算(五)Azkaban使用
在安装好Azkaban后,熟悉Azkaban的用法花了较长时间,也踩了一些坑,接下来将详细描述Azkaban的使用过程. 目录 一.界面介绍 二.Projects 1. 创建Command类型单一Jo ...
- 阿里图标库使用IconFont
1.注册账号登陆 2.创建项目 3.搜索想使用的图标,添加入库,或者上传自己的图标入库 4.在图标库中,将添加的图标加入项目 5.将项目图标下载至本地 6.下载文件为 包括三种格式,使用方法不同 Un ...
- nginx安装升级及配置详解
1.简介 2.安装配置 3.配置文件介绍 4.启动.停止.平滑重启.升级 一.Nginx简介 Nginx(engine x)是俄罗斯人Igor Sysoev编写的一款高性能的http和反向代理服务器. ...
- wifidog源码分析 - wifidog原理
wifidog是一个用于配合认证服务器实现无线网页认证功能的程序,常见的情景就是使用于公共场合的无线wifi接入点,首先移动设备会连接公共wifi接入点,之后会弹出网页要求输入用户名密码,认证过后才能 ...
- 快速排序的php实现
再来一个非常高级的排序算法,快速排序...这个算法是很高效的. 快速排序的思路是,找到一个分割点(中枢点 默认是列表第一个值),把原列表分隔成两部分,在分割点左侧的是都比它小的,在它右侧的是都比它大的 ...
- HDMI传输原理:TMDS
参考资料:http://blog.sina.com.cn/s/blog_679686370100vgg1.html: http://www.eeworld.com.cn/mndz/2011/0818/ ...
- HDMI接口的PCB设计
1.定义 HDMI的全称是“HighDefinitionMultimedia”,即:高清多媒体接口. HDMI在引脚上和DVI兼容,只是采用了不同的封装.与DVI相比.HDMI可以传输数字音频信号,并 ...
- linux 开机进入initramfs无法开机
4/4 用fsck命令开始检查.修复(fsck是个很好用了磁盘检测修复命令)输入:fsck -t ext4 /dev/sda1 (-t是指定文件系统类型:现在的多半是ext3和ext4,不知道,你就一 ...
- Luogu2612 ZJOI2012 波浪 DP
传送门 花掉了自己用来搞学科的时间做了这道题-- 一道类似的题:Here 考虑拆开绝对值计算贡献.那么我们对于\(1\)到\(N\)的排列,从小到大地将插入它们插入排列中. 假设我们现在计算到了数\( ...
- 实现Repeater控件的记录单选
有朋友问及,在Repeater控件中第一列放置一个RadioButton,实现对记录的单选. 下面Insus.NET想举个例子来实现与说明. 为Repeater控件准备数据: 在ASPX网页上,写好R ...