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的更多相关文章

  1. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  2. 【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 ...

  3. 【Cf #503 B】The hat(二分)

    为什么Cf上所有的交互题都是$binary \; Search$... 把序列分成前后两个相等的部分,每一个都可以看成一条斜率为正负$1$的折线.我们把他们放在一起,显然,当折线的交点的横坐标为整数时 ...

  4. 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

    比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...

  5. UOJ30——【CF Round #278】Tourists

    1.感谢taorunz老师 2.题目大意:就是给个带权无向图,然后有两种操作, 1是修改某个点的权值 2是询问,询问一个值,就是u到v之间经过点权的最小值(不可以经过重复的点) 操作数,点数,边数都不 ...

  6. 【CF刷题】14-05-12

    Round 236 div.1 A:只需要每个点连接所有比他大的点,知道边用完为止. //By BLADEVIL #include <cmath> #include <cstdio& ...

  7. UOJ #30. 【CF Round #278】Tourists

    Description Cyberland 有 n 座城市,编号从 1 到 n,有 m 条双向道路连接这些城市.第 j 条路连接城市 aj 和 bj.每天,都有成千上万的游客来到 Cyberland ...

  8. UOJ #30【CF Round #278】Tourists

    求从$ x$走到$ y$的路径上可能经过的最小点权,带修改  UOJ #30 $ Solution:$ 如果两个点经过了某个连通分量,一定可以走到这个连通分量的最小值 直接构建圆方树,圆点存原点的点权 ...

  9. 【Cf #449 C】Willem, Chtholly and Seniorious(set维护线段)

    这里介绍以个小$trick$,民间流传为$Old Driver Tree$,实质上就是$set$维护线段. 我们将所有连续一段权值相同的序列合并成一条线段,扔到$set$里去,于是$set$里的所有线 ...

随机推荐

  1. 02-Kubenetes资源

    目录 Kubenetes资源 常用资源对象 标签labels 创建资源的方式 Pod pods.spec.containers 必须 nodeSelector <map [string]stri ...

  2. 模拟器无Back、Menu等键

    问题如图所示: 解决方法: 1. 打开Android Virtual Device (AVD) Manager --> 选择模拟器,并点击edit --> 勾选KeyBoard中的选项,并 ...

  3. iOS程序员 如何提升核心竞争力,防止自己被裁员?

    前言: 核心竞争力最早由普拉哈拉德和加里·哈默尔两位教授提出,通常认为核心竞争力,即企业或个人相较于竞争对手而言所具备的竞争优势与核心能力差异, 说白了就是你的优势,而且最好是独一无二的的优势,这就是 ...

  4. FB的新专利竟要监看使用者的脸

    大家应该会很好奇Facebook又在搞什么新花招,这个专利的名称是"Techniques for emotion detection and content delivery",其 ...

  5. Windows 下配置 Vagrant 环境

    Vagrant是一个基于 Ruby 的工具,用于创建和部署虚拟化开发环境.它使用 Oracle 的开源VirtualBox虚拟化系统. Vagrant 在快速搭建开发环境方面是很赞的,试想一个团队中, ...

  6. java课堂 动手动脑3

    (1) 该函数没有赋初值再就是如果类提供一个自定义的构造方法,将导致系统不在提供默认的构造方法. (2) public class test { public static void main(Str ...

  7. python案例:使用if语句实现一个猜拳游戏

    任务要求: 在控制台中提示输入石头.剪刀.布,按回车键,然后给出游戏结果. 分析: 我们知道在游戏规则中,石头克剪刀,剪刀克布,布克石头.但是这在计算机中并不是很好直接的表示,因此我们分别用0.1.2 ...

  8. 浅谈osi模型 三次握手 四次挥手 ddos攻击原理

    C/S B/S 架构 C:client 端 B:browser 浏览器 S:server 端 C/S架构,基于客户端与服务端之间的通信 例如:QQ,抖音,快手,微信,支付宝等等 优点:个性化设置,响应 ...

  9. pycharm的安装配置及思维导图

    1.1 计算机基础知识 主板:人的骨架,用于扩展设备的 cpu:人的大脑,用于计算和逻辑处理的 硬盘:存储数据(永久存储) 电源:人的心脏 内存:存储数据(临时存储) 断电即消失 操作系统 xp wi ...

  10. 【模板】zkw线段树

    题意简述 已知一个数列,你需要进行下面两种操作: 1.将某一个数加上x 2.求出某区间每一个数的和 代码 #include <cstdio> using namespace std; in ...