题意:

  有n(n≤50000)支队伍参加了两场比赛,分别有两个排名。现在要求输出总排名,如果对任意m,在两个排名的前m个队伍都相同,那么在总排名前m个队伍就是这些队伍。其它情况按字典序排。


Solution:

  简单题。

  先map定位每个队伍在第一个排名中的位置。从第二个排名的第一个开始,找到最小满足条件的m,对这m个队伍按照字典序进行排序。然后继续找新的m(不包括排完序的队伍)直到所有队伍排完。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
map<string, int> pos;
vector<string> Rank;
int n;
int main()
{
ios::sync_with_stdio ( );
cin >> n;
string name;
for ( int i = ; i <= n; ++i ) {
cin >> name;
pos[name] = i;
}
int r = , l = ;
for ( int i = ; i <= n; ++i ) {
cin >> name;
Rank.push_back ( name );
r = max ( r, pos[name] );
if ( i == r ) {
sort ( Rank.begin() + l, Rank.begin() + r );
l = r;
}
}
for ( int i = ; i < n; ++i ) {
cout << Rank[i] << "\n";
}
}

SGU 281.Championship的更多相关文章

  1. redhat6.4安装MySQL-server-5.5.28-1.linux2.6.x86_64.rpm

    首先下载下面三个文件: MySQL-server-5.5.28-1.linux2.6.x86_64.rpm MySQL-client-5.5.28-1.linux2.6.x86_64.rpm MySQ ...

  2. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  3. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  4. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  5. SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...

  6. Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划

    C. Tennis Championship 题目链接 http://codeforces.com/contest/735/problem/C 题面 Famous Brazil city Rio de ...

  7. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

  8. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

  9. 树形DP求树的重心 --SGU 134

    令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心 ...

随机推荐

  1. Hive 0.12 Caused by: MetaException(message:Version information not found in metastore. )解决方法

    配置完成Mysql存储元数据信息,启动后测试show tables报错ERROR exec.DDLTask: org.apache.hadoop.hive.ql.metadata.HiveExcept ...

  2. How to Kill All Processes That Have Open Connection in a SQL Server Database[关闭数据库链接 最佳方法] -摘自网络

    SQL Server database administrators may frequently need in especially development and test environmen ...

  3. 对XML和YAML文件实现I/O操作

    1.文件的打开关闭 XML\YAML文件在OpenCV中的数据结构为FileStorage,打开操作例如: string filename = "I.xml"; FileStora ...

  4. html图片滚动效果

    分享一个手动控制图片左右滚动的代码 先说html部分,建立一个层,写出他的样式,层中在建立一个小一点的层用来存放需要滚动的图片,小层两边再建两个小层用来存放控制图片左右滚动的按钮.代码如下: 样式表: ...

  5. 获取datagrid中编辑列combobox的value值与text值

    var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'productid'}); var productname = $(ed ...

  6. linux shell突然显示-bash-4.1#的解决方法

    老沙昨天还登录这个linux服务器,并且命令行好好的,今天突然在linux shell中不显示路径了,显示为-bash-4.1#. 以下是老沙的解决方案 vim ~/.bash_profile 如果没 ...

  7. 解决TortoiseCVS中文乱码

    解决TortoiseCVS中文乱码必备,解决方法: 第一:卸载和TortoiseCVS安装一起安装的CVSNT. 第二:安装本版本CVSNT. CVSNT下载地址:http://down.51cto. ...

  8. iOS开发中WebP格式的64位支持处理

    几个月前我们项目中添加了对webp格式的处理.期间遇到了一些问题,这是当中的一个小的记录. 官方下载地址:https://code.google.com/p/webp/downloads/list 对 ...

  9. SQL Server查询数据库中所有的表名及行数

    SELECT a.name, b.rows FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id WHERE (a.type = ...

  10. [Javascript] Adding Shapes to Maps with Leaflet and GeoJSON

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...