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 ;
}

最新文章

  1. LINQ实现递归算法
  2. 详解JavaScript模块化开发
  3. 每天一个linux命令(6):mv命令
  4. knockout 监控数组的缺点
  5. 【Python】Python-skier游戏[摘自.与孩子一起学编程]
  6. 修改MySQL默认最大连接数
  7. ubuntu rc.local 无效 解决方案(转)
  8. [转载]Arguments
  9. ActiveMQ in Action(4) - Security
  10. SA 后缀数组
  11. js版九宫格拼图与启发式搜索(A*算法)
  12. 学习ASP.NET Core Razor 编程系列十五——文件上传功能(三)
  13. centos 7下安装jdk1.8
  14. scala的reduce
  15. Spring MVC 使用介绍(九)—— 异常处理
  16. JSF生命周期&amp;Facelets的生命周期
  17. 一次奇妙的http请求之旅
  18. .NET MVC后台发送post请求
  19. elasticsearch简单操作(二)
  20. 关于mysql 5.7 版本登录时出现错误 1045的随笔

热门文章

  1. 【iOS】The filename 未命名.ipa in the package contains an invalid character(s)
  2. [重磅开源] 比SingleR更适合的websocket 即时通讯组件---ImCore开源了
  3. netty使用EmbeddedChannel对channel的出入站进行单元测试
  4. linux字符设备驱动中内核如何调用驱动入口函数 一点记录
  5. 放出一批jsp图书管理系统图书借阅系统源码代码运行
  6. Appium+python自动化(二十七)-让你在手机找到溜冰一样的感觉666,溜得飞起来 - 低级滑动(超详解)
  7. AndroidSDK的目录详解
  8. JWT详解
  9. 实现API优先设计的重要性和实现方式
  10. SpringBoot中Shiro缓存使用Redis、Ehcache