【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) = ...
随机推荐
- js原生代码实现鼠标拖拽(超简单)
首先先来看这一张图 在这种图中,盒子的大小为512px,并且margin-left:-250px margin-top:140px;并通过一些样式让其在中部显示 这些样式都不是重要的,这里加个marg ...
- Java基础学习总结(54)——JSON和Map转换的工具类
在pom.xml文件中引入如下jar <dependency> <groupId>commons-lang</groupId> <artifactId> ...
- jQuery中$(document).ready()和window.onload的区别?
document.ready和document.load的区别?(JQ中的$(document).ready()和window.onload的区别?) window.onload,是采用DOM0级事件 ...
- LoadRunner--HTML与URL录制方式区别
Recording录制选项 这里提供了两个大类的录制方式: 1. HTML-based script基于HTML的脚本 这种方式录制出来的脚本是基于HTML基础的,为每个用户操作生成单独的步骤,这种脚 ...
- HDU 5237 Base64
Base64 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- sublime找到成对标签(Ctrl+Shift+")
sublime找到成对标签(Ctrl+Shift+") windows版本默认快捷键是Ctrl+Shift+" sublime text怎么突出显示成对标签 使用BracketHi ...
- HDU 2077 汉诺塔IV 递归 通项公式
刚刚做的HDU 2064很好找规律, 回忆一下: b[1] = 2; b[n] = b[n-1] *3 + 2; 可得b[n]= 3^n-1 不懂的传送门http://blog.csdn.net/mu ...
- 6、修改应用程序数码相框以支持自动关闭LCD
1. 修改数码相框以自动关闭LCD关闭LCD : 在读取触摸屏的函数中判断:如果15S内无数据,执行: echo auto > /sys/devices/platform/mylcd/power ...
- SpringBoot学习:获取yml和properties配置文件的内容(转)
项目下载地址:http://download.csdn.net/detail/aqsunkai/9805821 (一)yml配置文件: pom.xml加入依赖: <!-- 支持 @Configu ...
- 设置cell背景色和选中色
// 设置cell的背景色 UIView *bg = [[[UIView alloc] init] autorelease]; bg.backgroundColor = [UIColor colorW ...