【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学习笔记 - fgm练习 - 网页换肤
总结: 1. 点击按钮,div内部变色,边框保持颜色不变. 实现原理:其实本来就把background 和 border 分别设置了同一个颜色,看似是一个整体,其实本来就是分开的. 那么点击的时候,只 ...
- Instant Client 配置
Instant Client Download 选择 Instant Client for Microsoft Windows (32-bit) 由于PL/SQL Developer 不支持64b ...
- GridView与ArrayAdapter的结合
activity_main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...
- VS2012 打包部署程序
一. 下载 InstallShield 2015(支持VS2012) VS2012没有自带打包工具,所以要先下载并安装一个打包工具.我采用微软提供的打包工具: InstallShield2015 ...
- [Angular] Configurable Angular Components - Content Projection and Input Templates
We are going to have a modal component: <au-modal > </au-modal> And we can pass default ...
- Centos配置java环境
安装jdk JDK 是开发Java程序必须安装的软件,我们查看一下 yum 源里面的 JDK:yum list java* 选择适合本机的JDK,并安装:yum install java-1.7.0- ...
- MySQLDump在使用之前一定要想到的事情
MySQLDump经常用于迁移数据和备份. 下面创建实验数据,两个数据库和若干表create database db1 ;use db1;create table t1(id int primary ...
- HINTERNET应包含的头文件
#include <afxinet.h> DWORD status=0;DWORD dwLen=sizeof(DWORD); if(!HttpQueryInfo(hRequest,HTTP ...
- [NIO]用dawn发送接收HTTP请求
HTTP协议的下层使用的是tcp.所以我们建立一个tcp连接就能发送接收http请求.dawn底层使用了nio.可是经过dawn的封装之后,我们在编写代码的时候,就和使用普通的堵塞式socket一样 ...
- php 文件夹是否存在,不存在就创建
$lujing = "./nihao/wohao"; if(!is_dir($liujing)){ mkdir(iconv("UTF-8", "GBK ...