题意:判断利用给出的正方形是否能拼接出无限延伸的结构。

分析:正方形上的字母看做点,正方形看做有向边。

例如:

若上下两个正方形能拼接,需要B+~C+是个有向边。

对输入的处理是:把A+,A-分别映射成2n+1,2n,利用(2n)^1 = 2n+1 , (2n+1)^1 = 2n 的性质处理有向边。

若存在有向环则unbounded,即不存在拓扑排序

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
char s[];
int pic[MAXN][MAXN];
int vis[MAXN];
priority_queue<int> q;
int get_id(char a, char b){
return b == '+' ? * (a - 'A') + : * (a - 'A');
}
bool dfs(int x){
vis[x] = -;
for(int i = ; i < ; ++i){
if(pic[x][i]){
if(vis[i] == -) return false;
else if(!vis[i] && !dfs(i)) return false;
}
}
vis[x] = ;
return true;
}
bool toposort(){
for(int i = ; i < ; ++i){
if(!vis[i] && !dfs(i)){
return false;
}
}
return true;
}
int main(){
int n;
while(scanf("%d", &n) == ){
memset(pic, , sizeof pic);
memset(vis, , sizeof vis);
while(n--){
scanf("%s", s);
for(int i = ; i < ; ++i){//处理除了00之外的点之间的有向边的关系
for(int j = ; j < ; ++j){
if(i != j && s[i * ] != '' && s[j * ] != ''){
int from = get_id(s[i * ], s[i * + ]) ^ ;
int to = get_id(s[j * ], s[j * + ]);
pic[from][to] = ;
}
}
}
}
bool ok = toposort();
if(ok){
printf("bounded\n");
}
else{
printf("unbounded\n");
}
}
return ;
}

UVA - 1572 Self-Assembly(图论模型+拓扑排序)的更多相关文章

  1. 图论之拓扑排序 poj 2367 Genealogical tree

    题目链接 http://poj.org/problem?id=2367 题意就是给定一系列关系,按这些关系拓扑排序. #include<cstdio> #include<cstrin ...

  2. 图论之拓扑排序 poj1128 Frame Stacking

    题目网址 http://poj.org/problem?id=1128 思路:遍历找出每一种字母出现的最大和最小的横纵坐标,假如本应出现字母A的地方出现了字母B,那么A一定在字母B之前,这就相当于点A ...

  3. UVA 10305:Ordering Tasks(拓扑排序)

    #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm& ...

  4. tsort - 拓扑排序

    tsort - 拓扑排序 本文链接:http://codingstandards.iteye.com/blog/834572   (转载请注明出处) 用途说明 tsort命令通常用于解决一种逻辑问题, ...

  5. UVA 1572 Self-Assembly(拓扑排序)

    1 // 把一个图的所有结点排序,使得每一条有向边(u,v)对应的u都排在v的前面. 2 // 在图论中,这个问题称为拓扑排序.(toposort) 3 // 不难发现:如果图中存在有向环,则不存在拓 ...

  6. UVa 1572 Self-Assembly (拓扑排序)

    题目链接: https://cn.vjudge.net/problem/UVA-1572 Automatic Chemical Manufacturing is experimenting with ...

  7. UVa 1572 Self-Assembly (构造+拓扑排序。。。。。)

    题意:给定n个带标号的正方形,标号要么是一个大写字母加一个+或-,要么是00, 当且仅当大写字母相同并且符号相反时可以连接,问你给定的能不能拼成一个无限大的的东西. 析:说实话,真心没有看出来是拓扑排 ...

  8. uvalive 6393(uva 1572) Self-Assembly 拓扑排序

    题意: 给出一些正方形,这些正方形的每一条边都有一个标号.这些标号有两种形式:1.一个大写字母+一个加减号(如:A+, B-, A-......), 2.两个0(如:00):这些正方形能够任意翻转和旋 ...

  9. 拓扑排序的 +Leapms 线性规划模型

    知识点 拓扑排序 拓扑排序的+Leapms模型 无圈有向图 一个图G(V,E), 如果边有向且不存在回路,则为无圈有向图.在无圈有向图上可以定义拓扑排序.下图是一个无圈有向图的例子. 拓扑排序 给定一 ...

随机推荐

  1. scala的trait执行报错: 错误: 找不到或无法加载主类 cn.itcast.scala.`trait`

    scala的trait执行报错: 错误: 找不到或无法加载主类 cn.itcast.scala.`trait`.Children 原因:包名写成了trait,与trait关键字重名了: package ...

  2. MySQL : INSERT INTO SELECT

    INSERT INTO wx_announcement_push ( title, content, STATUS, del_flag, user_login_name ) SELECT '大家好', ...

  3. Python学习 —— 爬虫入门 - 爬取Pixiv每日排行中的图片

    更新于 2019-01-30 16:30:55 我另外写了一个面向 pixiv 的库:pixiver 支持通过作品 ID 获取相关信息.下载等,支持通过日期浏览各种排行榜(包括R-18),支持通过 p ...

  4. R语言 一个向量的值分派给另一个向量

    group = sample(seq(1,10),size = 20,replace = T) #这20个组分别属于1,...,10 v = rnorm(length(unique(group)),0 ...

  5. pdf.js-----后端返回utf-8数据流,前端处理数据展示pdf

    需求:做项目联调接口时,发现知识库展示pdf未果,经与后端人员沟通,发现以下问题: 1.接口返回的是utf-8数据流,但是前端调用的是base64解析方法: 导致功能有误: 方案一:将后端返回的utf ...

  6. IDEA导入项目后,导入artifacts 方法 以及 Spring的配置文件找不到的解决方法

    我们一般选择 open 项目,如果没有artifacts 的添加选项,我们就要选择 import 项目. 如果没有artifacts ,项目下面会有错误提示,点击错误提示Fix,设置里面导入artif ...

  7. python之闭包,装饰器

    目录 函数对象 :相当于变量名 函数对象的作用: 1. 可以引用 2. 可以作为函数的返回值 3. 可以作为容器的元素 4. 可以作为函数的参数 闭包 定义: 如果在一个函数的内部定义了另一个函数,外 ...

  8. keep-alive 用法 及activated,deactivated这两个生命周期函数

    keep-aliveProps: include - 字符串或正则表达式.只有名称匹配的组件会被缓存.exclude - 字符串或正则表达式.任何名称匹配的组件都不会被缓存.max - 数字.最多可以 ...

  9. 5、mysql的连接查询

    1.内联查询 >inner join 或 join 2.外联查询 (1)左连接 >left outer join 或 left join (2)右连接 >right outer jo ...

  10. JDK8中的ConcurrentHashMap源码

    背景 上文JDK8中的HashMap源码写了HashMap,这次写ConcurrentHashMap ConcurrentHashMap源码 /** * Maps the specified key ...