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网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...
随机推荐
- vue(5)联动+tab页
来自:https://juejin.im/post/5a0c191f6fb9a04514639419 1.联动 新增 <input v-model="msg" /> & ...
- vuex 浅认知
什么是Vuex? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式. 采用了集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 什么情况下我应该使用 ...
- my26_Slave failed to initialize relay log info structure from the repository
重启了一下从库,忘记先stop slave ,直接mysqladmin shutdown关闭实例,结果起不来了 mysql> start slave;ERROR 1872 (HY000): Sl ...
- js生成随机码(只含有数字和字母的随机码)
/*** randomWord 产生任意长度随机字母数字组合** randomFlag 是否任意长度 min 任意长度最小位[固定位数] max 任意长度最大位*/ function randomWo ...
- Silverlight 动态创建Enum
private Type CreateEnum() { List<string> lists = new List<string>(); lists.Add("男&q ...
- GBDT,FM,FFM推导
GBDT推导: https://xgboost.readthedocs.io/en/latest/tutorials/model.html FM,FFM推导: https://tech.meituan ...
- 性能测试工具LoadRunner19-LR之Controller IP欺骗
概念 IP地址欺骗是指用户操作产生的IP数据包为伪造的源IP地址,以便冒充其他系统或发件人的身份.这是一种黑客的攻击形式,黑客使用一台计算机上网,而借用另外一台机器的IP地址,从而冒充另外一台机器与服 ...
- git跟svn 服务端对比
Git已经火了很久,简单的使用也没有问题,但有几个问题一直以来都没有搞清楚:git跟svn有哪些异同,两者相互的优劣是什么,git的分布式怎么理解,为什么有离线提交,,,自己动手,分别看一下服务端跟客 ...
- contiki源码阅读之mmem.c
上次我们说了list,这次我们就借着mmem.c的代码来用一下这个链表. 代码目录是./core/lib/mmem.c 结构体定义如下 struct mmem { struct mmem *next; ...
- ETL模型设计
传统的关系数据库一般采用二维数表的形式来表示数据,一个维是行,另一个维是列,行和列的交叉处就是数据元素.关系数据的基础是关系数据库模型,通过标准的SQL语言来加以实现. 数据仓库是多维数据库,它扩展了 ...