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 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.
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
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.
优先队列来做,想起来那个病人优先级那个题了。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = 1e4+;
struct node{
char s[];
int g;
friend bool operator < (node A,node B){
return A.g<B.g;
}
};
priority_queue<node> p[maxn];
void solve(){
int n,m;
scanf("%d%d", &n,&m);
for(int i = ; i<=n; i++){
int r;
node nod;
scanf("%s%d%d", nod.s,&r,&nod.g);
p[r].push(nod);
}
for(int i = ; i<=m; i++){
node nod1,nod2,nod3;
nod1 = p[i].top();
p[i].pop();
nod2 = p[i].top();
p[i].pop();
if(p[i].size()>){
nod3 = p[i].top();
p[i].pop();
if(nod2.g == nod3.g){
printf("?\n");
}
else{
printf("%s %s\n",nod1.s,nod2.s);
}
} else printf("%s %s\n",nod1.s,nod2.s);
}
}
int main()
{
solve();
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 ...
- Codeforces 659B Qualifying Contest【模拟,读题】
写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...
- codeforces 659B Qualifying Contest
题目链接:http://codeforces.com/problemset/problem/659/B 题意: n个人,m个区.给出n个人的姓名(保证不相同),属于的区域,所得分数.从每个区域中选出成 ...
- B. Qualifying Contest_排序
B. Qualifying Contest time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 659 - A/B/C/D/E/F/G - (Undone)
链接:https://codeforces.com/contest/659 A - Round House - [取模] AC代码: #include<bits/stdc++.h> usi ...
- codeforces659B
Qualifying Contest CodeForces - 659B Very soon Berland will hold a School Team Programming Olympiad. ...
- Codeforces Round #346 (Div. 2) B题
B. Qualifying Contest Very soon Berland will hold a School Team Programming Olympiad. From each of t ...
随机推荐
- hdu_1848_Fibonacci again and again(博弈sg函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:给你3堆石子,每次只能取fibonacci数的石子,问先手是否能赢 题解:SG函数模版题 ...
- PMBok项目管理
这就是项目管理的九大领域:整合管理.范围管理.时间管理.费用管理.质量管理.人力资源管理.沟通管理.风险管理.采购管理. 项目管理好像一头大象,将其大卸九块之后,要装进冰箱就容易多了. 看看书上是怎样 ...
- HDU 5965 三维dp 或 递推
题意:= =中文题 思路一:比赛时队友想的...然后我赛后想了一下想了个2维dp,但是在转移的时候,貌似出了点小问题...吧?然后就按照队友的思路又写了一遍. 定义dp[i][j][k],表示第i列, ...
- Fatal error: Class ‘mysqli’ not found in解决办法
在使用[$conn = new \mysqli($servername, $username, $password,$dbname);]连接msql数据库的时候 出现错误:[Fatal error: ...
- Perl资料
一 官网 http://www.perl.org/ 三 资料 http://www.slideshare.net/ggilmour/perl-development-sample-courseware ...
- 笨方法学python--数字和数学计算
1 数学运算符号 + plus 加号 - minus 减号 / slash 除法 * asterisk 乘法 % percent 模除 求余 < less than 小于号 > great ...
- 【dp 背包变形】 poj 1837
#include <cstdio> #include <memory.h> #include<iostream> using namespace std; ][]; ...
- CAPSPageMenu分页交互
最近在开发过程中,我的前任在处理类似于新闻多板块的界面,在一个视图控制器里加载多个UITableView以显示不同类型的信息,并可通过头部按钮和左右滑动来切换不同的tableView这样的界面中,采取 ...
- OpenGL----绘制立方体,定点数组与顶点缓冲
,立方体是很简单,但是这里只是拿立方体做一个例子,来说明OpenGL在绘制方法上的改进.从原始一点的办法开始一个立方体有六个面,每个面是一个正方形,好,绘制六个正方形就可以了. glBegin(GL_ ...
- Servlet Filter 过滤器
Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源: 例如Jsp, Servlet, 静态图片文件或静态 ht ...