传送门:QAQQAQ

题意:有两个数组,一个数组有n个数,另一个数组有m个数。s[i][j]表示第一个数组第i个数和第二个数组第j个数的大小关系,要求构造出一种方案,使条件成立。

先考虑没有等于号的情况,那么就是裸的拓扑排序,现在多了一个等于号,就先进行并查集再拓扑就行了。

•注意点:1.在进行拓扑排序时一定要全部用father[x]作为节点

                2.一定要全部并查集做完以后再连边,否则可能刚连完father[x]就变了

 #include<bits/stdc++.h>
using namespace std;
const int N=;
typedef pair<int,int> pii; int p[N],a[N];
int n,m,judge=;
int t[N],ans[N],b[N];
char s[][];
vector <int> v[]; int f(int x)
{
if(p[x]==x) return x;
return p[x]=f(p[x]);
} void unite(int x,int y)
{
int xx=f(x),yy=f(y);
p[yy]=p[xx];
} int main()
{
memset(b,,sizeof(b));
memset(t,,sizeof(t));
scanf("%d %d",&n,&m);
for(int i=;i<=n+m;i++) p[i]=i;
for(int i=;i<=n;i++)
{
scanf("%s",s[i]+);
for(int j=;j<=m;j++)
{
if(s[i][j]=='=')
{
unite(i,j+n);
}
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(s[i][j]=='>') v[f(j+n)].push_back(f(i)),t[f(i)]++;
else if(s[i][j]=='<') v[f(i)].push_back(f(j+n)),t[f(j+n)]++;
}
}
priority_queue<pii> q;
for(int i=;i<=n+m;i++) if(f(i)==i) judge++;
for(int i=;i<=n+m;i++)
{
if(!t[p[i]]&&!b[p[i]])
{
q.push(make_pair(p[i],));
b[p[i]]=;
}
}
int sum=,num=;
while(!q.empty())
{
int now=q.top().first,w=q.top().second;
q.pop(); sum++;
ans[now]=w;
for(int i=;i<v[now].size();i++)
{
int pos=v[now][i];
t[pos]--;
if(!t[pos])
{
q.push(make_pair(pos,w+));
}
}
}
if(sum<judge)
{
puts("No");
return ;
}
puts("Yes");
for(int i=;i<=n;i++) printf("%d ",ans[p[i]]); puts("");
for(int i=n+;i<=m+n;i++) printf("%d ",ans[p[i]]); puts("");
return ;
}

codeforces 1131D-Gourmet choice的更多相关文章

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

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

  2. coderfoces D. Gourmet choice

      D. Gourmet choice time limit per test 2 seconds memory limit per test 256 megabytes   题目链接: https: ...

  3. D. Gourmet choice并查集,拓扑结构

    D. Gourmet choice time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. codeforces #541 D. Gourmet choice(拓扑+并查集)

    Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the wo ...

  5. Codeforces 1154C Gourmet Cat

    题目链接:http://codeforces.com/problemset/problem/1154/C 题目大意: 主人有一只猫.周一&周四&周日:吃鱼周二&周六:吃兔子周三 ...

  6. Codeforces 589F Gourmet and Banquet

    A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet kno ...

  7. 【CF #541 D】 Gourmet choice

    link:https://codeforces.com/contest/1131 题意: 给定一些大小比较,输出排名. 思路: 这道题我用的是拓扑排序,又因为有等于号的存在,我用了并查集. 结束后这道 ...

  8. codeforces 589F. Gourmet and Banquet 二分+网络流

    题目链接 给你n种菜, 每一种可以开始吃的时间不一样, 结束的时间也不一样. 求每种菜吃的时间都相同的最大的时间.时间的范围是0-10000. 看到这个题明显可以想到网络流, 但是时间的范围明显不允许 ...

  9. CF1131D Gourmet choice

    题目链接 题意 有两组菜,第一组有\(n\)种,第二组有\(m\)种.给出一个\(n\times m\)的矩阵,第\(i\)行第\(j\)列表示第一组中的第\(i\)种菜与第二组中的第\(j\)种菜好 ...

  10. CF1131D Gourmet choice(并查集,拓扑排序)

    这题CF给的难度是2000,但我感觉没这么高啊…… 题目链接:CF原网 题目大意:有两个正整数序列 $a,b$,长度分别为 $n,m$.给出所有 $a_i$ 和 $b_j(1\le i\le n,1\ ...

随机推荐

  1. uoj139 【UER #4】被删除的黑白树

    题目 不难发现有一个暴力\(dp\) 设\(dp[x][l]\)表示\(x\)点子树内所有叶子节点到\(x\)的路径上都有\(l\)和黑点时最多能染多个黑点 转移就是 \[dp[x][l]=\max( ...

  2. 字符串KMP算法

    讲解:http://blog.csdn.net/starstar1992/article/details/54913261 #include <bits/stdc++.h> using n ...

  3. JAVA-基础(Stream流)

    说起stream流大家的第一反应是io,但是实际上谁规定流一定是存在io包里呢?在java8中得益于Lambda表达式的函数式编程,引入了一个全新的概念,stream. 1.优势? 在java8之前我 ...

  4. Python中虚拟环境venv的基本用法

    环境windows 7 venv为python3中的默认库,无需安装. 创建新的venv方法, 在当前文件夹下执行cmd,输入如下代码 python -m venv bob bob为需要创建的文件夹名 ...

  5. day15 python-03 列表,元组,字典

    Python之路,Day3 = Python基础3 注: extend: 拼接 enumerate:打印序号,返回两个值 模块的简单使用 sys模块 #!/usr/bin/env python #这句 ...

  6. LUOGU P2294 [HNOI2005]狡猾的商人(差分约束)

    [传送门] (https://www.luogu.org/problemnew/show/P2294) 解题思路 差分约束.先总结一下差分约束,差分约束就是解决一堆不等式混在一起,左边是差的形式,右边 ...

  7. Linux课程---16、apache虚拟主机设置(如何在一台服务器上配置三个域名)

    Linux课程---16.apache虚拟主机设置(如何在一台服务器上配置三个域名) 一.总结 一句话总结:有三个网站www.lampym.com,bbs.lampym.com,mysql.lampy ...

  8. Kafka和RabbitMQ 对比

    1)  Kafka成为业界大数据松耦合架构,异步,队列 特点:吞吐量高50m/s. Kafka和RabbitMQ都是MQ机制,它差异 Kafka作为大数据产品,可以作为数据源,也可以作为结果数据中转 ...

  9. HttpUrlConnection使用详解--转AAAAA

    http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpConnection.html HttpUr ...

  10. 同步+TASK异步请求

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...