传送门: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. innodb_file_per_table 理解

    MYSQL innodb存储引擎 默认将所有的数据库 innodb 引擎的表数据存储在一个共享空间中:ibdata1,当增删数据库的时候, ibdata1文件不会自动收缩,单个数据库的备份也会成为问题 ...

  2. 利用DNSQuery 进行DNS查询

    #include <WinSock2.h> #include <WinDNS.h> #pragma comment (lib, "Dnsapi.lib") ...

  3. postgresql使用pg_dump和pg_restore 实现跨服务器的数据库迁移或备份

    因为业务需求,需要将服务器上的postgre多个数据库的数据整个库得迁移到另一个postgre数据库上. 一般表较少时,会使用postgre 的copy to 和 copy from 命令就能完成表的 ...

  4. CF773E Blog Post Rating

    题意:有一篇博客.一共有n个人,心中有他们期望该博客得到的赞数a[i].当某个时刻该博客的获赞数<a[i],则该人会使得赞数+1,当赞数>a[i],该人会使得赞数-1,当赞数=a[i],不 ...

  5. kubernetes监控和性能分析工具:heapster+influxdb+grafana

    1.部署heapster 下载 heapster 相关 yaml 文件 [root@master dashboard]# wget https://raw.githubusercontent.com/ ...

  6. 学习servlet之路--javax-servlet不存在

    我在编译一个servlet菜鸟教程下提供的包含有javax.servlet包的java文件,变异出错, import java.io.*;import javax.servlet.*;import j ...

  7. linxu(centos)安装php-fpm

    编译安装php-fpm 安装前准备 yum -y install gcc automake autoconf libtool make yum -y install gcc gcc-c++ glibc ...

  8. <Python基础>列表的基本操作

    s = 'abCDeFg aBcDea' s1 = s.split('D',3) #以s1列表为例 print(s1) #增 s1.append('foxabc') #返回值None,直接增到列表的最 ...

  9. 12-6-上下文this

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Ifconfig- Linux必学的60个命令

    1.作用 ifconfig用于查看和更改网络接口的地址和参数,包括IP地址.网络掩码.广播地址,使用权限是超级用户. 2.格式 ifconfig -interface [options] addres ...