Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
地址:http://codeforces.com/contest/782/problem/D
题目:
2 seconds
256 megabytes
standard input
standard output
Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.
Each club's full name consist of two words: the team's name and the hometown's name, for example, "DINAMO BYTECITY". Innokenty doesn't want to assign strange short names, so he wants to choose such short names for each club that:
- the short name is the same as three first letters of the team's name, for example, for the mentioned club it is "DIN",
- or, the first two letters of the short name should be the same as the first two letters of the team's name, while the third letter is the same as the first letter in the hometown's name. For the mentioned club it is "DIB".
Apart from this, there is a rule that if for some club x the second option of short name is chosen, then there should be no club, for which the first option is chosen which is the same as the first option for the club x. For example, if the above mentioned club has short name "DIB", then no club for which the first option is chosen can have short name equal to "DIN". However, it is possible that some club have short name "DIN", where "DI" are the first two letters of the team's name, and "N" is the first letter of hometown's name. Of course, no two teams can have the same short name.
Help Innokenty to choose a short name for each of the teams. If this is impossible, report that. If there are multiple answer, any of them will suit Innokenty. If for some team the two options of short name are equal, then Innokenty will formally think that only one of these options is chosen.
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league.
Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20.
It it is not possible to choose short names and satisfy all constraints, print a single line "NO".
Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.
If there are multiple answers, print any of them.
2
DINAMO BYTECITY
FOOTBALL MOSCOW
YES
DIN
FOO
2
DINAMO BYTECITY
DINAMO BITECITY
NO
3
PLAYFOOTBALL MOSCOW
PLAYVOLLEYBALL SPB
GOGO TECHNOCUP
YES
PLM
PLS
GOG
3
ABC DEF
ABC EFG
ABD OOO
YES
ABD
ABE
ABO
In the first sample Innokenty can choose first option for both clubs.
In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.
In the third example Innokenty can choose the second options for the first two clubs, and the first option for the third club.
In the fourth example note that it is possible that the chosen short name for some club x is the same as the first option of another club y if the first options of x and y are different.
思路:先找出并标记第一类队名有重复的所有队,这些队只能使用第二类队名(这些队名暂记为B),如果这些队的第二类队名重复就无解。
然后处理剩下的第一类队名没重复的队(记为A),本来是这些队是可以直接选第一类队名的,但是因为这些第一类队名可能和先处理的第二类队名重复,所以要进行以下处理:
1.判断有无第一队名和先前处理的第二类队名重复的,有则判断此时选择第二类是否可行,可行就将该队加入B中,不行就无解。无重复的队先不处理。
2.因为新B队中可能和A队中有重复的,所以要重复执行步骤1,直到AB中没重复的。
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e5+;
const int mod=1e9+; int n,ans,same[],sh[];
char sa[][],sb[][];
map<string,int>hs;//hs哈希队名,hs[x]记录哈希值为x的第一个出现的队的序号
string ss,sc[]; int main(void)
{
cin>>n;
ss="sac";
for(int i=,cnt=;i<=n;i++)
{
scanf("%s%s",&sa[i][],&sb[i][]);
ss[]=sa[i][],ss[]=sa[i][],ss[]=sa[i][];
if(hs[ss]) same[i]=,same[sh[hs[ss]]]=;
else hs[ss]=cnt,sh[cnt++]=i;
}
hs.clear();
for(int i=;i<=n;i++)
if(same[i])//先处理第二类
{
ss[]=sa[i][],ss[]=sa[i][],ss[]=sb[i][];
if(hs[ss])
{
ans=;break;
}
hs[ss]=,sc[i]=ss;
}
while()//再循环处理第一类队名和第二类队名中重复的
{
bool ff=;
for(int i=;i<=n;i++)
if(!same[i])
{
ss[]=sa[i][],ss[]=sa[i][],ss[]=sa[i][];
if(hs[ss])
{
ss[]=sb[i][];
if(hs[ss])
{
printf("NO\n");
return ;
}
same[i]=;
ff=;
hs[ss]=;
}
sc[i]=ss;
}
if(ff)
break;
}
for(int i=;i<=n;i++)//处理剩下的
if(!same[i])
{
ss[]=sa[i][],ss[]=sa[i][],ss[]=sa[i][];
sc[i]=ss;
}
if(ans)
printf("NO\n");
else
{
printf("YES\n");
for(int i=;i<=n;i++)
cout<<sc[i]<<endl;
}
return ;
} /*
3
abc abc
abc dce
abd ebc
*/
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League的更多相关文章
- 【2-SAT】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
先反复地扫(不超过n次),把所有可以确定唯一取法的给确定下来. 然后对于剩下的不能确定的,跑2-SAT.输出可行解时,对于a和¬a,如果a所在的强连通分量序号在¬a之前,则取a,否则不取a.如果a和¬ ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map
A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals )D. Innokenty and a Football League(2-sat)
D. Innokenty and a Football League time limit per test 2 seconds memory limit per test 256 megabytes ...
- 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E
http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...
- 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D
http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab
地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons
地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...
随机推荐
- ReactNative iOS源码解析
http://awhisper.github.io/2016/06/24/ReactNative%E6%B5%81%E7%A8%8B%E6%BA%90%E7%A0%81%E5%88%86%E6%9E% ...
- Python爬虫(八)
源码: import requests import re from my_mysql import MysqlConnect import time,random # 获取招聘详情链接 def ge ...
- 1-2、superset国际化
最近由于工作需要研究开源可视化项目superset,由于其国际化做不怎么好,故而记录下国际化的过程,本篇本着『授人以鱼不如授人以渔』的原则,只叙述国际化的过程及方法,不提供直接的国际化文件. 为了方便 ...
- webstorm配置内存参数,解决卡顿
找到WebStorm.exe.vmoptions这个文件,路径如下webstorm安装主目录>bin>WebStorm.exe.vmoptions更改为第二行:-Xms526m第三行:-X ...
- JZOJ.5315【NOIP2017模拟8.19】小串串
Description
- codevs 5962 [SDOI2017]数字表格
输入描述 Input Description [题解] 对于蓝色部分预处理前缀积. 然后在用除法分块搞一下. O(Q*sqrt(min(n,m))*logn+nlogn) #include<c ...
- JsBridge的异步不执行的处理--promise异步变同步
Hybird App:H5内嵌APP,前端用vue,APP之间的交互处理,适配安卓ios, 为了降低开发成本,减少前端适配工作量,三端统一使用 WebViewJavascriptBridge 在进行 ...
- ps -aux | egrep 多个值
ps -aux |egrep "(schedule.jar|positec.jar|time_server.jar|tomcat-xweb/)"
- Struts2的表单标签还可以为集合中的对象赋值
•Struts 还允许填充 Collection 里的对象, 这常见于需要快速录入批量数据的场合 代码如下 : TestCollectionAction.java package com.atgu ...
- 引入 netty网关,向flume提交数据
netty 处理http请求 package com.test; import io.netty.bootstrap.ServerBootstrap;import io.netty.channel. ...