CF - 1131 D Gourmet choice
先把 = 的人用并查集合并在一起。
然后 < > 的建边, 跑一遍 toposort 之后就好了。
入度为0点的值肯定为1, 然后就是因为这个是按照时间线走过来的,所以一个点的最小值,就是在入队的那一刻确定的, 即入度为0的时候,值就是现在的值+1。
注意就是不要同一个点入队多次。
代码:
/*
code by: zstu wxk
time: 2019/02/24
*/
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e3 + ;
int pre[N];
int ind[N];
int val[N];
int n, m;
char s[N][N];
vector<int> vc[N];
int Find(int x){
if(x == pre[x]) return x;
return pre[x] = Find(pre[x]);
}
queue<int> q;
void toposort(){
for(int i = ; i <= n+m; ++i){
// cout << i << ' ' << ind[i] << endl;
if(i == Find(i) && ind[i] == ) {
q.push(i), val[i] = ;
// cout << i << endl;
}
}
while(!q.empty()){
int x = q.front();
q.pop();
for(int v : vc[x]){
ind[v]--;
if(ind[v] == ){
val[v] = val[x] + ;
q.push(v); }
}
}
}
void Ac(){
for(int i = ; i <= n + m; ++i) pre[i] = i, ind[i] = ;
for(int i = ; i <= n; ++i){
scanf("%s", s[i]+);
for(int j = ; j <= m; ++j){
if(s[i][j] == '='){
int u = Find(i), v = Find(n+j);
if(u == v) continue;
pre[u] = v;
}
}
}
for(int i = ; i <= n; ++i){
for(int j = ; j <= m; ++j){
if(s[i][j] == '=' ) continue;
int u = Find(i), v = Find(n+j);
if(s[i][j] == '<'){
vc[u].pb(v);
ind[v]++;
}
else {
vc[v].pb(u);
ind[u]++;
}
}
}
toposort();
for(int i = ; i <= n+m; ++i){
if(!val[Find(i)]){
puts("No");
return ;
}
}
puts("Yes");
for(int i = ; i <= n; ++i){
printf("%d%c", val[Find(i)]," \n"[i==n]);
}
for(int i = ; i <= m; ++i){
printf("%d%c", val[Find(i+n)], " \n"[i==m]);
}
}
int main(){
while(~scanf("%d%d", &n, &m)){
Ac();
}
return ;
}
CF - 1131 D Gourmet choice的更多相关文章
- CF#541 D. Gourmet choice /// BFS 拓扑
题目大意: 给定n m 第一行有n个数 第二行有m个数 接下来n行每行m列 有 = < > 位于 i j 的符号表示 第一行第i个数与第二行第j个数的大小关系 1.将n+m个数 当做按顺序 ...
- coderfoces D. Gourmet choice
D. Gourmet choice time limit per test 2 seconds memory limit per test 256 megabytes 题目链接: https: ...
- D. Gourmet choice并查集,拓扑结构
D. Gourmet choice time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- 【CF #541 D】 Gourmet choice
link:https://codeforces.com/contest/1131 题意: 给定一些大小比较,输出排名. 思路: 这道题我用的是拓扑排序,又因为有等于号的存在,我用了并查集. 结束后这道 ...
- codeforces #541 D. Gourmet choice(拓扑+并查集)
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the wo ...
- CF1131D Gourmet choice(并查集,拓扑排序)
这题CF给的难度是2000,但我感觉没这么高啊…… 题目链接:CF原网 题目大意:有两个正整数序列 $a,b$,长度分别为 $n,m$.给出所有 $a_i$ 和 $b_j(1\le i\le n,1\ ...
- CF1131D Gourmet choice
题目链接 题意 有两组菜,第一组有\(n\)种,第二组有\(m\)种.给出一个\(n\times m\)的矩阵,第\(i\)行第\(j\)列表示第一组中的第\(i\)种菜与第二组中的第\(j\)种菜好 ...
- CF 1131 E. String Multiplication
E. String Multiplication 题意 分析: 从后往前考虑字符串变成什么样子. 设$S_i = p_1 \cdot p_2 \dots p_{i}$,最后一定是$S_{n - 1} ...
随机推荐
- Spring Boot中自定义注解+AOP实现主备库切换
摘要: 本篇文章的场景是做调度中心和监控中心时的需求,后端使用TDDL实现分表分库,需求:实现关键业务的查询监控,当用Mybatis查询数据时需要从主库切换到备库或者直接连到备库上查询,从而减小主库的 ...
- spring cloud eureka + feign,api远程调用
网上教程不少,有些就是复制粘贴,不结合实际生产. eureka不再阐述. 一般正常开发会有多个工程,且多个module. 我的习惯是: eureka server.权限.config.gateway ...
- wscript.shell 使用
<%@ Page Language="VB" validateRequest = "false" aspcompat = "true" ...
- Unity基于NGUI的简单并可直接使用的虚拟摇杆实现(一)
可能大家都听说过大名鼎鼎的easytouch,然而easytouch是基于UGUI的,两种不同的UI混用,可能会造成项目管理的混乱,并且可能会出现各种幺蛾子,比如事件传递互相扰乱的问题. 于是就想找一 ...
- .netcore持续集成测试篇之开篇简介及Xunit基本使用
系列目录 为了支持跨平台,微软为.net平台提供了.net core test sdk,这样第三方测试框架诸如Nunit,Xunit等只需要按照sdk提供的api规范进行开发便可以被dotnet cl ...
- linux CPU100%异常排查
1.top查找出占CPU比例最高的进程(5881): 2.查看该进程正在执行的线程: top -H -p 5881 3.将线程转换成16进制 printf ‘%x\n’ 5950 4.查看异常线程执 ...
- unity 四叉树管理场景
当场景元素过多时,需要实时的显示及隐藏物体使得性能提示,但是物体那么多,怎么知道哪些物体需要显示,哪些物体不需要显示的.当然,遍历物体判断该物体是否可以显示是最容易想到的方法,但是每次更新要遍历所有物 ...
- Mermaid
graph TD; A-->B; A-->C; B-->D; C-->D;
- DT-06 For Homekit
一. 配置DT-06上网 连接此热点,会自动弹出wifi配置页面. 输入选中的路由密码,点 Join加入,如果路由没有出现在列表中,点 Other手工输入(仅支持2.4g路由配置) 二.配置dt-06 ...
- 约会安排 HDU - 4553(线段树区间查询,区间修改,区间合并)
题目: 寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会.与此同时,也有很多基友找他开黑, ...