【题目链接】: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的更多相关文章

  1. 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 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 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 ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. Android 软键盘弹出,界面整体上移的问题

    AndroidManifest.xml文件中界面对应的<activity>里加入android:windowSoftInputMode="adjustPan" 键盘就会 ...

  2. Java核心技术 卷Ⅰ 基础知识(4)

    第六章 接口与内部类 接口 特性 接口与抽象类 对象克隆 接口与回调 内部类 使用内部类访问对象状态 内部类的特殊语法规则 局部内部类 匿名内部类 静态内部类 代理 Class[] in=new Cl ...

  3. pragma pack,字节对齐

    关于字节对齐 pragma pack 一. 测试代码: // packTest.cpp : Defines the entry point for the console application. / ...

  4. Shiro基础知识08----拦截器介绍(转)

    1 拦截器介绍 Shiro使用了与Servlet一样的Filter接口进行扩展:所以如果对Filter不熟悉可以参考<Servlet3.1规范>http://www.iteye.com/b ...

  5. 黑马day18 jquery高级特性&amp;Ajax的load方法

    介绍jquery中的load方法: (1).前面没有jquery.修饰,能够判断出他是一个普通的非全局函数(也就是说是一个局部函数):$.,$().,jquery.等修饰的就是全局函数.没有这些修饰的 ...

  6. js课程 2-7 for-in循环怎么使用

    js课程 2-7 for-in循环怎么使用 一.总结 一句话总结:用的是in的作用加上for的作用,相当于一个组合技. 1.js中in运算符的作用是什么? 判断一个元素是否在一个集合或者对象中 1.a ...

  7. php面试题四

    php面试题四 一.总结 二.php面试题四 01. 输出为 Mozilla/4.0(compatible;MSIE5.01;Window NT 5.0)时,可能的输出语句是:   A.$_S ...

  8. 【转】移动Web开发-点击事件及页面滚动

    点击事件 移动端浏览器点击事件默认有300ms的延迟 移动端实现弹性滚动 安卓局部滚动 滚动条出现bug,解决方案:Android只是用全局滚动 模拟全局滚动,加上padding-top及paddin ...

  9. pppoe-环境下的mtu和mss

    路由器上在宽带拨号高级设置页面会有设置数据包MTU的页面 数据包MTU(字节):1480 (默认是1480,如非必要,请勿修改) PPPoE/ADSL:1492 ,可以尝试修改为1492 MTU: M ...

  10. mysql去除字段内容的空格和换行回车

    MySQL 去除字段中的换行和回车符 解决方法:          UPDATE tablename SET field = REPLACE(REPLACE(field, CHAR(10), ''), ...