【codeforces 782D】 Innokenty and a Football League
来源:互联网 发布:青山软件破解版 编辑:程序博客网 时间:2024/06/05 05:49
【题目链接】: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;}
1 0
- 【codeforces 782D】 Innokenty and a Football League
- codeforces D. Innokenty and a Football League
- Codeforces 782D Innokenty and a Football League【贪心】
- CodeForces 782D Innokenty and a Football League
- Codeforces 780D-Innokenty and a Football League
- 【Codeforces 780 D Innokenty and a Football League 】+ 模拟 + 贪心
- CodeForces 780D Innokenty and a Football League【模拟+贪心】
- D. Innokenty and a Football League----map
- D. Innokenty and a Football League
- D.Innokenty and a football league
- codeforces 782D Innokenty and a Football League(2-SAT)
- Codeforces Round #403 D. Innokenty and a Football League(思维+模拟)
- Codeforce 403 D. Innokenty and a Football League
- codeforce D. Innokenty and a Football League 贪心,模拟
- Codeforce 780D Innokenty and a Football League (贪心+模拟)
- codeforces 781B. Innokenty and a Football League(贪心)
- CF 782D. Innokenty and a Football League 贪心,思维,模拟
- 【Codeforces Round #403】Codeforces 781B Innokenty and a Football League
- Pillow学习之ImageDraw
- 数学常识汇总
- JDK提供的Arrays的几个减少重复造轮子的方法
- Makefile常用函数
- Pillow学习之ImageEnhance
- 【codeforces 782D】 Innokenty and a Football League
- 深入理解java线程池
- ROS总结——创建ROS工作空间
- Pillow学习之ImageFilter
- HRBUST1212-乘积最大
- jQuery选择器总结
- Java IO 基础
- bean 验证介绍
- Pillow学习之ImageFont