The following is the current ranking rules for the ICPC Asia EC Online Qualifiers, and there will be two online contests.
- In each contest, only the rank of the top-ranked team from each university will be taken as the score of that university;
- In each contest, participating universities will be ranked according to their scores;
- The two rankings of universities are combined using the merge sorting method. For any two universities that obtain the same ranking in different contests, the university that received this ranking in the first contest will be ranked first.
- Delete duplicate universities and obtain the final ranking of all participating universities (only the highest rankings for each university are retained).
Now assuming that there are n teams in the first contest and m teams in the second contest.
For each contest, given the ranking of each team and the university to which it belongs, please output the final ranking of all participating universities according to the above rules.
You can better understand this process through the sample.
The first line contains two integers n,m (1≤n,m≤1e4) , representing the number of teams participating in the first contest and the second contest.
Then following n lines, the i-th line contains a string si (1≤∣si∣≤10) only consisting of uppercase letters, representing the abbreviation of the university to which the i-th ranked team in the first contest belongs.
Then following m lines, the i-th line contains a string ti (1≤∣ti∣≤10) only consisting of uppercase letters, representing the abbreviation of the university to which the i-th ranked team in the second contest belongs.
It’s guaranteed that each university has only one abbreviation.
Output several lines, the i-th line contains a string, representing the abbreviation of the i-th ranked university in the final ranking.
You should ensure that the abbreviation of any participating universities appears exactly once.
- 14 10
- THU
- THU
- THU
- THU
- XDU
- THU
- ZJU
- THU
- ZJU
- THU
- NJU
- WHU
- THU
- HEU
- PKU
- THU
- PKU
- PKU
- ZJU
- NUPT
- THU
- NJU
- CSU
- ZJU
- THU
- PKU
- XDU
- ZJU
- NJU
- NUPT
- WHU
- HEU
- CSU
Sample is part of the results in 2022 ICPC Asia EC Online Contest.
In the first contest, the ranking of the universities is:
- THU
- XDU
- ZJU
- NJU
- WHU
- HEU
In the second contest, the ranking of the universities is:
- PKU
- THU
- ZJU
- NUPT
- NJU
- CSU
By combining these two rankings according to the rules, the rankings of the universities is:
- THU
- PKU
- XDU
- THU
- ZJU
- ZJU
- NJU
- NUPT
- WHU
- NJU
- HEU
- CSU
By deleting duplicate universities we will get the final ranking.
解析:
首先对于两个榜单,统计并且去重。
然后对于榜单a和b进行遍历,并且记录是否重复。
注意,有的学校可能没参加某一场,所以可能导致两场榜单去重之后长度不一样。
- #include
- using namespace std;
- typedef long long ll;
- const int N=1e5+5;
- int n,m;
- string s;
- vector
a,b,res; - set
p; - int main(){
- scanf("%d%d",&n,&m);
- for(int i=1;i<=n;i++){
- cin>>s;
- if(p.count(s)==0){
- p.insert(s);
- a.push_back(s);
- }
- }
- p.clear();
- for(int i=1;i<=m;i++){
- cin>>s;
- if(p.count(s)==0){
- p.insert(s);
- b.push_back(s);
- }
- }
- p.clear();
- for(int i=0;i<min(a.size(),b.size());i++){
- if(a[i]==b[i]){
- p.insert(a[i]);
- }
- else{
- if(p.count(a[i])==0){
- p.insert(a[i]);
- }
- if(p.count(b[i])==0){
- cout<
- p.insert(b[i]);
- }
- }
- }
- for(int i=min(a.size(),b.size());i<max(a.size(),b.size());i++){
- if(a.size()>b.size()){
- if(p.count(a[i])==0){
- p.insert(a[i]);
-
-
相关阅读:
C++标准模板(STL)- 类型支持 ()
TSINGSEE智能分析网关V4车辆结构化数据检测算法及车辆布控
区块链架构下,智慧城市加速发展
C语言-基础
QTday04(事件)
通过串口实现printf函数,中断实现串口数据接收
WIFI6E中的MESH组网功能
05.SpringBoot依赖管理你学会了吗
[附源码]java毕业设计户籍管理系统
【顺序表的实现】
-
原文地址:https://blog.csdn.net/JungleZRD/article/details/132955222
-
最新文章
-
沪漂五周年了:我越来越迷茫了
Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
MySQL-Seconds_behind_master的精度误差
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
Agent OS :五种驯服不确定性的范式
PortSwigger SQL注入LAB11
数据库即时编译JIT
[Begin]AI Learn Data Day 0
深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU