【codeforces 782D】 Innokenty and a Football League
【题目链接】:http://codeforces.com/contest/782
【题意】
每个队名有两种选择,
然后第一个选择队名相同的那些队只能选第二种;
让你安排队名
【题解】
首先全都选成第一种队名;
然后第一种队名相同的队,它们只能全都变成选第二种队名的了;
这个时候如果第一种队名相同的那些队里面,变成第二种队名后有重复的,直接输出无解;
这个时候先不管第一种队名
之后再处理第一种队名;
看看第一种队名有没有和第二种队名重的;
如果有重的话就让他变到第二种队名;
以此法贪心就好
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e3 + 100;
int n, ans = 1,now;
string s1, s2;
string ts1[N], ts2[N];
int zt[N];
map <string, vector<int> > dic1,dic2;
map <string, int > di1, di2;
map <string, bool> haved;
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n);
rep1(i, 1, n)
{
cin >> s1 >> s2;
ts1[i] = "",ts1[i] += s1.substr(0, 3);
ts2[i] = "", ts2[i] += s1.substr(0, 2);
ts2[i] += s2[0];
dic1[ts1[i]].push_back(i);
di1[ts1[i]]++;
}
rep1(i,1,n)
if (!haved[ts1[i]])
{
int len = dic1[ts1[i]].size();
if (len > 1)
{
rep1(j, 0, len - 1)
{
di1[ts1[i]]--;
int idx = dic1[ts1[i]][j];
zt[idx] = 1;
di2[ts2[idx]]++;
if (di2[ts2[idx]] > 1)
return puts("NO"), 0;
}
}
haved[ts1[i]] = true;
}
while (1)
{
bool ok = true;
rep1(j,1,n)
if (zt[j] == 0)
{
if (di2[ts1[j]])
{
ok = false;
if (di2[ts2[j]])
return puts("NO"), 0;
else
{
zt[j] = 1;
di2[ts2[j]] = 1;
}
}
}
if (ok) break;
}
puts("YES");
rep1(i, 1, n)
{
if (zt[i] == 0)
cout << ts1[i] << endl;
else
cout << ts2[i] << endl;
}
return 0;
}
【codeforces 782D】 Innokenty and a Football League的更多相关文章
- 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 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- BlobTracker
Blob分析介绍 分类: CV相关2012-11-04 11:25 1929人阅读 评论(5) 收藏 举报 Blob翻译成中文,是“一滴”,“一抹”,“一团”,“弄脏”,“弄错”的意思.在计算机视觉中 ...
- 【例 7-12 UVA - 1343】The Rotation Game
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 迭代加深搜索. 每次抽动操作最多只会让中间那一块的区域离目标的"距离"减少1. 以这个作为剪枝. 枚举最大深度. ...
- 洛谷 P1657 选书
P1657 选书 题目描述 学校放寒假时,信息学奥赛辅导老师有1,2,3……x本书,要分给参加培训的x个人,每人只能选一本书,但是每人有两本喜欢的书.老师事先让每个人将自己喜欢的书填写在一张表上.然后 ...
- 阿里云部署Docker(3)----指令学习
通过上两节的学习http://blog.csdn.net/minimicall/article/details/40119177 和http://blog.csdn.net/minimicall/ar ...
- StringBuilder和String的区别
使用 StringBuilder 语言 C# String 对象是不可改变的.每次使用 System.String 类中的方法之一时,都要在内存中创建一个新的字符串对象,这就需要为 ...
- jmeter--使用badboy录制脚本
JMeter录制脚本有多种方法,其中最常见的方法是用第三方工具badboy录制,另外还有JMeter自身设置(Http代理服务器+IE浏览器设置)来录制脚本,但这种方法录制出来的脚本比较多且比较乱,个 ...
- java和 javaw 以及 javaws的区别
http://blog.csdn.net/topwqp/article/details/8595936
- 一起talk C栗子吧(第八回:C语言实例--素数)
各位看官们,大家好,从今天開始.我们讲大型章回体科技小说 :C栗子,也就是C语言实例. 闲话休提, 言归正转. 让我们一起talk C栗子吧! 看官们.上一回中咱们说的是进制转换的样例,这一回咱们说的 ...
- 关于Altium Designer重新修改某一原件pcb封装的问题
在重新导入的时候可能会影响到类class,所以可能是原理图中没有类吧 上图中的comment的修改是表示下面图片中的 comment栏的改变:
- 四种卸载Mac软件的方法
从 Mac 电脑上卸载已经安装的应用程序可能是你知道的操作系统里面最简单的一种了.而如果你是一名新买了 Mac 电脑的用户,那么你可能比较困惑:怎么没有控制面板中的相应板块来卸载它们呢?但是其实你想不 ...