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} ...
随机推荐
- Eclipse "R cannot be resolved"问题
前两天 Eclipse 又遇到了这个问题.网上找了不少,不过最终还是没能解决我的问题,无奈重装了 Eclipse…… 搜索中找到了下面这几篇文章,常见的解决方法都在这里,还是不错的,分享一下: htt ...
- Where is the clone one and how to extract it?
One cannot be in two places at once. Do you know what's "Dual Apps"? Manufactures like Xia ...
- Linux vim基本的使用方法
一.vim 的三种模式 (1) 插入模式 在插入模式中,才能输入文字:要进入插入模式,可以按键 “i”:如果要进入插入模式时,直接切换到下一行,可以输入“o”: (2) 命令模式 在命令模式中,主要进 ...
- Git应用之eclipse解决冲突代码
最近上班公司框架换成了微服务下面是eclipse 对代码进行管理 1.冲突代码 如果两个人在一个项目上同一文件上更改代码就会出现冲突现象 先用NewFile.jsp 文件做演示 打开eclipse从 ...
- Resource 使用详解
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...
- oracle常规使用(一)
目录 特殊sql distinct 项目中遇到表中无主键,但是某个字段不能重复. 需要匹配id串里的内容 批量更新,但是批量成功返回的是-1 时间格式化 行列互转 应用场景 列转行 总结 oracle ...
- 【win】【qt5安装】【qt5.5.1安装及第一个示例make错误】
[前言] 昨天按照需求将qt程序从linux系统移植到win上使用(其实有点缪论了,本人linux用的中标麒麟系统对于发布发布系统版本麒麟(注:以下用麒麟代替中标麒麟,什么银河麒麟,优麒麟的,我现在只 ...
- ES 26 - 通过partial update局部更新索引文档 (partial update增量修改原理)
目录 1 什么是partial update 1.1 全量修改文档的原理 1.2 修改指定field的思路 1.3 partial update的优势 1.4 partial update的使用 2 ...
- p2p 打洞专场(转)
就像1000个人眼中有1000个哈姆雷特一样,每个人眼中的区块链也是不一样的!作为技术人员眼中的区块链就是将各种技术的融合,包括密码学,p2p网络,分布式共识机制以及博弈论等.我们今天就来讨论一下区块 ...
- Node.js爬虫实战 - 爬你喜欢的
前言 今天没有什么前言,就是想分享些关于爬虫的技术,任性.来吧,各位客官,里边请... 开篇第一问:爬虫是什么嘞? 首先咱们说哈,爬虫不是"虫子",姑凉们不要害怕. 爬虫 - 一种 ...