【CF #541 D】 Gourmet choice
link:https://codeforces.com/contest/1131
题意:
给定一些大小比较,输出排名。
思路:
这道题我用的是拓扑排序,又因为有等于号的存在,我用了并查集。
结束后这道题惨遭fst,因为我拓扑排序本应只放入一个集合的代表点,但是我放入了多次。
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> /* ⊂_ヽ
\\ Λ_Λ 来了老弟
\('ㅅ')
> ⌒ヽ
/ へ\
/ / \\
レ ノ ヽ_つ
/ /
/ /|
( (ヽ
| |、\
| 丿 \ ⌒)
| | ) /
'ノ ) Lノ */ using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c); const ll oo = 1ll<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e8;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;} /*-----------------------showtime----------------------*/ const int maxn = 1e3+;
char mp[maxn][maxn];
int fa[maxn*];
int find(int x){
if(fa[x] == x) return x;
return fa[x] = find(fa[x]);
}
void uni(int x,int y){
int fx = find(x);
int fy = find(y);
if(fx == fy) return ;
fa[fx] = fy;
}
int ans[maxn*],tmp[maxn*];
int du[maxn*],vis[maxn*];
vector<int>G[maxn*];
int main(){
int n,m;
scanf("%d%d", &n, &m);
rep(i, , n) scanf("%s", mp[i] + );
rep(i, , n+m) fa[i] = i; rep(i, , n) {
rep(j, , m) {
if(mp[i][j] == '=') uni(i, j+n);
}
} rep(i, , n) {
rep(j, , m) {
if(mp[i][j] == '=') continue;
int u = find(i), v = find(j+n);
if(mp[i][j] == '>'){
du[u]++;
G[v].pb(u);
}
else {
du[v]++;
G[u].pb(v);
}
}
}
queue<pii>que;
for(int i=; i<=n+m; i++){
if(du[find(i)] == && vis[find(i)] == )
{
que.push(pii(find(i),)),vis[find(i)] = ,tmp[find(i)] = ;
}
} while(!que.empty()){
int u = que.front().fi;int s = que.front().se; que.pop(); for(int i=; i<G[u].size(); i++){
int v = G[u][i];
du[v] --;
if(du[v] == && vis[v] == ) {
tmp[v] = s+;
que.push(pii(v, s+));
vis[v] = ;
}
}
} int flag = ;
for(int i=; i<=n+m; i++) if(vis[find(i)] == ) flag = ;
if(flag == ) puts("No");
else {
puts("Yes");
for(int i=; i<=n; i++) printf("%d ", tmp[find(i)]);
puts("");
for(int i=; i<=m; i++) printf("%d ", tmp[find(i+n)]);
puts("");
}
return ;
}
【CF #541 D】 Gourmet choice的更多相关文章
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- 【39.68%】【CF 714 C】Filya and Homework
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【Cf #503 B】The hat(二分)
为什么Cf上所有的交互题都是$binary \; Search$... 把序列分成前后两个相等的部分,每一个都可以看成一条斜率为正负$1$的折线.我们把他们放在一起,显然,当折线的交点的横坐标为整数时 ...
- 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...
- UOJ30——【CF Round #278】Tourists
1.感谢taorunz老师 2.题目大意:就是给个带权无向图,然后有两种操作, 1是修改某个点的权值 2是询问,询问一个值,就是u到v之间经过点权的最小值(不可以经过重复的点) 操作数,点数,边数都不 ...
- 【CF刷题】14-05-12
Round 236 div.1 A:只需要每个点连接所有比他大的点,知道边用完为止. //By BLADEVIL #include <cmath> #include <cstdio& ...
- UOJ #30. 【CF Round #278】Tourists
Description Cyberland 有 n 座城市,编号从 1 到 n,有 m 条双向道路连接这些城市.第 j 条路连接城市 aj 和 bj.每天,都有成千上万的游客来到 Cyberland ...
- UOJ #30【CF Round #278】Tourists
求从$ x$走到$ y$的路径上可能经过的最小点权,带修改 UOJ #30 $ Solution:$ 如果两个点经过了某个连通分量,一定可以走到这个连通分量的最小值 直接构建圆方树,圆点存原点的点权 ...
- 【Cf #449 C】Willem, Chtholly and Seniorious(set维护线段)
这里介绍以个小$trick$,民间流传为$Old Driver Tree$,实质上就是$set$维护线段. 我们将所有连续一段权值相同的序列合并成一条线段,扔到$set$里去,于是$set$里的所有线 ...
随机推荐
- 【iOS】receiver type *** for instance message is a forward declaration
错误原因:没有引入相关的头文件 http://stackoverflow.com/questions/8815200/receiver-type-for-instance-message-is-a-f ...
- hdoj 3732 Ahui Writes Word (多重背包)
之前在做背包的题目时看到了这道题,一看,大喜,这不是裸裸的01背包吗!! 然后华丽丽的超时,相信很多人也和我一样没有考虑到数据量的大小. 时隔多日,回过头来看这道题,依旧毫无头绪....不过相比之前 ...
- FB的新专利竟要监看使用者的脸
大家应该会很好奇Facebook又在搞什么新花招,这个专利的名称是"Techniques for emotion detection and content delivery",其 ...
- Filebeat6.3文档—Log input配置
Filebeat6.3文档-Log input配置 paths 日志加载的路径.例如加载某一子目录级别下面路径的日志:/var/log/*/*.log.这表示会去加载以.log结尾的/var/log下 ...
- Android--SharedPreferences数据存储方案
SharedPreferences是使用键值对的形式存储的,并且支持多种不同的数据类型,存的是String,取得值也是String. 使用SharedPreferenc ...
- 【0808 | Day 11】文件的高级应用/修改以及函数的定义/使用/参数
文件的高级应用 一.三种模式 'r+'模式 with open('test.py','r',encoding = 'utf8') as fr: print(fr.writable()) fr.writ ...
- 用python实现银行家算法
编制模拟银行家算法的程序,并以下面给出的例子验证所编写的程序的正确性. 进程 已占资源 最大需求数 资源种类 A B C D A B C D P0 0 0 1 2 0 0 1 2 P1 1 0 0 0 ...
- c语言实现基本的数据结构(三) 栈
#include <stdio.h> #include <tchar.h> #include <stdlib.h> #define StackSize 5 #def ...
- Django-内置用户系统
Django自带的用户认证 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括 1.用户注册 2.用户登录 3.用户认证 4.注销 5.修改密码 Django作为一个 ...
- Mybatis-Spring扫描路径有重叠导致Invalid bound statement(not found)问题
背景 近日,某个系统的测试环境mybatis总是报Invalid bound statement(not found)异常,导致tomcat容器无法启动.异常信息如下: org.apache.ibat ...