codeforces 659B B. Qualifying Contest(水题+sort)
题目链接:
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
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.
题意:
给这么人的名字,来自的地区和分数,从每个地区选分数最高的两个人,要求其他人的分数都比他两小;
思路:
按地区和分数排序,再判断第二名和第三名的分数就好啦;
AC代码:
/*
2014300227 659B - 45 GNU C++11 Accepted 577 ms 8432 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+;
struct node
{
string str;
int pos,num;
};
node po[N];
int cmp(node x,node y)
{
if(x.pos==y.pos)return x.num>y.num;
return x.pos<y.pos;
}
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
cin>>po[i].str>>po[i].pos>>po[i].num;
}
sort(po,po+n,cmp);
if(po[].pos==po[].pos)
{
if(po[].num==po[].num)cout<<"?"<<"\n";
else cout<<po[].str<<" "<<po[].str<<"\n";
}
else
{
cout<<po[].str<<" "<<po[].str<<"\n";
}
po[n].pos=po[n-].pos;
po[n].num=-;
for(int i=;i<n-;i++)
{
if(po[i].pos==po[i-].pos)continue;
if(po[i+].pos==po[i+].pos)
{
if(po[i+].num==po[i+].num)cout<<"?"<<"\n";
else cout<<po[i].str<<" "<<po[i+].str<<"\n";
}
else cout<<po[i].str<<" "<<po[i+].str<<"\n";
}
return ;
}
codeforces 659B B. Qualifying Contest(水题+sort)的更多相关文章
- Codeforces Round #346 (Div. 2) B. Qualifying Contest 水题
B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Be ...
- CodeForces 681A A Good Contest (水题)
题意:给定 n 个人和before, after的分数,让你找 before 的分数大于等于2400并且before 小于 after. 析:看完题意就知道怎么算了吧..不用说了 #include & ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- codeforces 710A A. King Moves(水题)
题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...
随机推荐
- Oracle 使用TRUNCATE TABLE删除所有行
若要删除表中的所有行,则 TRUNCATE TABLE 语句是一种快速.有效的方法.TRUNCATE TABLE 与不含 WHERE 子句的 DELETE 语句类似.但是,TRUNCATE TABLE ...
- [ 转]C++ 虚函数表解析
http://blog.csdn.net/haoel/article/details/1948051 前言 C++中的虚函数的作用主要是实现了多态的机制.关于多态,简而言之就是用父类型别的指针指向其子 ...
- IOS研究之网络编程(二)-Cocoa Streams使用具体解释
本文以及相关的系列文章是我总结的iOS网络开发方面的知识点,本文是第二篇,主要分析了Cocoa Streams中的几个重要类 Cocoa Streams实际上是Objective-C对CFNet ...
- java 中 wait和notify的用法
package com.test; public class OutputThread { public static Object lockObj=new Object(); public stat ...
- 精彩回顾 HUAWEI HiAI 亮相华为北研所
从普通照片变成艺术品,仅需3秒: 从随手拍下的讲解胶片到生成规整清晰的ppt,只要瞬间…… 5月25日在华为北京研究所举办的HUAWEI HiAI技术合作交流会上,伴随着一声声惊叹,数款接入HUA ...
- python 基础 4.3 高阶函数下和匿名函数
一 .匿名函数 顾名思议就是没有名字的函数,那为什么要设立匿名函数,他有什么作用呢?lambda 函数就是一种快速定义单行的最小函数,可以用在任何需要函数的地方. 常规版: def fun(x,y ...
- HIbernate 注解 mappedBy 与 inverse
hibernate中 配置文件中的inverse属性意思就是放弃控制权 ,主导权由对方控制,也就是说 我方进行的删除等操作不会影响到对方 即使设置了cascadeType.ALL 这个解释其实就是hi ...
- 九度OJ 1160:放苹果 (DFS)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:998 解决:680 题目描述: 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和 ...
- iOS 设置字体样式
1.iOS设置字体样式 label.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24]; 字体名如下: F ...
- 点聚-weboffice 6.0 (三)
1.页面 var filename="<%=request.getParameter("filePath").toString()%>"; docu ...