CF #541div2 D
题目本质:形成一个拓扑图,不应带自环。
解决方法:
1.先把等于号的部分用dsu缩点;
2.大于和小于号建立拓扑关系;
3.n*m的矩阵,只要用标号n+j代表m集合的第j个就从二维降到一维了;
4.dfs查有没有环:used == 2的那种环是合法的!
void dfs(int i) {
used[i] = ;
for (int s : v[i]) {
if (used[s] == ) {
puts("No");
exit();
}
if (!used[s]) dfs(s);
}
used[i] = ;
order.push_back(i);
}
5.按照order记录的拓扑顺序自底向上dp一下最小取值。
总代码:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <fstream>
#define ri readint()
#define gc getchar()
#define R(x) scanf("%d", &x)
#define W(x) printf("%d\n", x)
#define init(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define irep(i, a, b) for (int i = a; i >= b; i--)
#define ls p << 1
#define rs p << 1 | 1
using namespace std; typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18; inline int readint() {
int x = , s = , c = gc;
while (c <= ) c = gc;
if (c == '-') s = -, c = gc;
for (; isdigit(c); c = gc)
x = x * + c - ;
return x * s;
} const int maxn = 1e3 + ;
int n, m;
int value[maxn << ];
int used[maxn << ];
int fa[maxn << ];
char cmp[maxn][maxn];
vector<int> v[maxn << ], order; int getf(int v) {
return v == fa[v] ? v : fa[v] = getf(fa[v]);
} void merge(int x, int y) {
int p = getf(x), t = getf(y);
fa[p] = t;
} void dfs(int i) {
used[i] = ;
for (int s : v[i]) {
if (used[s] == ) {
puts("No");
exit();
}
if (!used[s]) dfs(s);
}
used[i] = ;
order.push_back(i);
} int main() {
ios_base::sync_with_stdio(false);
cin.tie(); cin >> n >> m;
rep(i, , n + m) {
fa[i] = i;
} rep(i, , n) {
rep(j, , m) {
cin >> cmp[i][j];
if (cmp[i][j] == '=') {
merge(i, n + j);
}
}
} rep(i, , n) {
rep(j, , m) {
int x = getf(i), y = getf(n + j);
if (cmp[i][j] == '>') {
v[x].push_back(y);
} else if (cmp[i][j] == '<') {
v[y].push_back(x);
}
}
} rep(i, , n + m) {
if (fa[i] != i)
continue;
if (!used[i]) {
dfs(i);
}
}
for (int i : order) {
int val = ;
for (int j : v[i]) {
val = max(val, value[j]);
}
value[i] = val + ;
} cout << "Yes\n";
rep(i, , n) {
cout << value[getf(i)] << " ";
}
cout << endl;
rep(i, , m) {
cout << value[getf(n + i)] << " ";
}
return ;
}
CF #541div2 D的更多相关文章
- CF #541div2 F
题目本质:并查集的链式合并 解决方法1: 类似哈夫曼树,叶节点们为真点,其余造一些虚的父节点,使得dfs这棵树的时候,先进行并查合并的点一定是兄弟节点因而紧挨着被输出,巧妙达到了效果. #pragma ...
- CF #541div2 E
题目本质:忽略串的变化,只记载26个字母的相关变化. 解决方法: 在上一次与本次的转移过程中,情况并不多,主要取决于本次串的首尾字母,若不是本次的首尾字母,会被置1:如果是的话,分情况接一下并更新.另 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
随机推荐
- ThinkPHP使用方法与心得
ThinkPHP相信PHP程序员对它并不陌生,通过自己的学习在此发表个人看法,也为以后自己查找ThinkPHP方面的知识更加方便. 一.mvc及数据库CURD操作流程: 1.新建数据库:数据库名称:1 ...
- windows下的host文件在哪里,有什么作用?
在Window系统中有个Hosts文件(没有后缀名),在Windows98系统下该文件在Windows目录,在Windows2000/XP系统中位于C:\Winnt\System32\Drivers\ ...
- phpcms v9中的$CATEGORYS栏目数组
首先 如果不能用$CATEGORYS这个数组或掉不出来内容应加入 $CATEGORYS = getcache('category_content_1','commons'); 1.用途 $CATEGO ...
- vue 表单验证省市县三联动
<el-col :span="24"> <el-form-item label="所在地区" prop="region" ...
- linux下配置jdk+tomcat
安装软件包 下载jdk和tomacat安装包,我这里使用的是jdk-8u144-linux-x64.tar.gz和apache-tomcat-8.5.23.tar.gz. 分别解压这两个安装包,用命令 ...
- 3.1 HiveServer2.Beeline JDBC使用
https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients 一.HiveServer2.Beeline 1.HiveSer ...
- UVa 1658 Admiral (最小费用流)
题意:给定一个图,求1-n的两条不相交的路线,并且权值和最小. 析:最小费用流,把每个结点都拆成两个点,中间连一条容量为1的边,然后一个作为入点,另一个是出点.最后跑两次最小费用流就行了. 代码如下: ...
- 走进VR游戏开发的世界
http://geek.csdn.net/news/detail/76504 我们组在2014年下半年尝试开发了一款Xbox One平台的体感游戏,2015年上半年进行收尾工作的同时,结合之前积累的体 ...
- 51nod1625(枚举&贪心)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
- 康少带你python项目从部署到上线云服务器
首先,服务器要安装nginx和mysql,网站文件建议放在/usr/local/www,环境python3.6+mysql5.7,阿里云的服务器可以用公共镜像有一个配置好的,不然就自己装一下环境吧. ...