【例题 6-19 UVA - 1572】Self-Assembly
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
旋转和翻转,会发现。
如果可以顺着某个方向一直放的话。
总是能转换成往下或者往右连的。
则只要能够出现一个连接顺序的循环,则总是有解的。
->转化成图论模型
如果一个正方形有A+
另外一个正方形有A-B+C+D-
那么从A+连3条边分别到B+,C+,D-
按照这样的方式连,如果能出现一个环的话,肯定是有解的
->有一条边,就已经说明能够新增加一个正方形了。
拓扑排序判环即可
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 52;
const int NN = (int) 4e4;
int n,tot;
map <string,int> mmap;
int g[N+10][N+10],du[N+10],num;
bool bo[N+10];
vector <int> v[NN+100];
queue <int> dl;
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
for (char i = 'A';i <= 'Z';i++){
string temp ="";
temp+= i;temp += '-';
mmap[temp] = ++tot;
}
for (char i = 'A';i <= 'Z';i++){
string temp = "";
temp += i;temp += '+';
mmap[temp] = ++tot;
}
for (int i = 1;i <= NN;i++) v[i].resize(4);
while ( cin >> n ){
memset(g,0,sizeof g);
memset(du,0,sizeof du);
memset(bo,0,sizeof bo);
for (int ii = 1;ii <= n;ii++){
string s;
cin >> s;
string temp = "";
for (int i = 0,j = 0;i < 7;i+=2,j++){
temp = s.substr(i,2);
v[ii][j] = mmap[temp];
bo[v[ii][j]] = 1;
}
}
for (int ii = 1;ii <= n;ii++){
for (int i = 0;i < 4;i++){
if (v[ii][i]==0) continue;
int x = (v[ii][i]>26)?(v[ii][i]-26):(v[ii][i]+26);
if (!bo[x]) continue;
for (int j = 0;j <4 ;j++)
if (i!=j){
int y = v[ii][j];
if (y==0) continue;
if (!g[x][y]){
du[y]++;
}
g[x][y] = 1;
}
}
}
num = 52;
for (int i = 1;i <= 52;i++)
if (du[i]==0){
dl.push(i);
du[i] = -1;
}
while (!dl.empty()){
num--;
int x = dl.front();
dl.pop();
for (int i = 1;i <= 52;i++)
if (g[x][i]){
g[x][i] = g[i][x] = 0;
du[i]--;
if (du[i] == 0){
dl.push(i);
}
}
}
if (num!=0){
cout << "unbounded" << endl;
}else{
cout << "bounded" << endl;
}
}
return 0;
}
【例题 6-19 UVA - 1572】Self-Assembly的更多相关文章
- UVA 1572 Self-Assembly(拓扑排序)
1 // 把一个图的所有结点排序,使得每一条有向边(u,v)对应的u都排在v的前面. 2 // 在图论中,这个问题称为拓扑排序.(toposort) 3 // 不难发现:如果图中存在有向环,则不存在拓 ...
- uva 1572 self-assembly ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxQAAANxCAYAAAB9uv94AAAgAElEQVR4nOxdPW7tOpLWFrQGJb72vI ...
- UVa 1572 (拓扑排序) Self-Assembly
题意: 有n种正放形,每种正方形的数量可视为无限多.已知边与边之间的结合规则,而且正方形可以任意旋转和反转,问这n中正方形是否可以拼成无限大的图案. 分析: 首先因为可以旋转和反转,所以可以保证在拼接 ...
- UVA 1572 Self-Assembly
拓扑排序,以边上标号为点,正方形为边,拓扑图中存在有向环时unbounded,否则bounded: 注意:仔细处理输入: 遍历一个点时,下一次遍历拼上的下一个方形边:即假设遍历到 A+ 时,下次从 ...
- UVa 1572 Self-Assembly (拓扑排序)
题目链接: https://cn.vjudge.net/problem/UVA-1572 Automatic Chemical Manufacturing is experimenting with ...
- UVa 1572 Self-Assembly (构造+拓扑排序。。。。。)
题意:给定n个带标号的正方形,标号要么是一个大写字母加一个+或-,要么是00, 当且仅当大写字母相同并且符号相反时可以连接,问你给定的能不能拼成一个无限大的的东西. 析:说实话,真心没有看出来是拓扑排 ...
- Uva 1572 自组合
贴个源码// UVa1572 Self-Assembly // Rujia Liu #include<cstdio> #include<cstring> #include< ...
- uvalive 6393(uva 1572) Self-Assembly 拓扑排序
题意: 给出一些正方形,这些正方形的每一条边都有一个标号.这些标号有两种形式:1.一个大写字母+一个加减号(如:A+, B-, A-......), 2.两个0(如:00):这些正方形能够任意翻转和旋 ...
- UVA - 1572 Self-Assembly(图论模型+拓扑排序)
题意:判断利用给出的正方形是否能拼接出无限延伸的结构. 分析:正方形上的字母看做点,正方形看做有向边. 例如: 若上下两个正方形能拼接,需要B+~C+是个有向边. 对输入的处理是:把A+,A-分别映射 ...
随机推荐
- 强悍的 vim —— 删除空行、删除注释以及加注释解注释
强悍的 vim -- 删除空行.删除注释以及加注释解注释 原文 https://blog.csdn.net/lanchunhui/article/details/51588198 1. 删除空行空行的 ...
- js插件---layer.js使用体验是怎样
js插件---layer.js使用体验是怎样 一.总结 一句话总结:只有jquery和js,没有css,使用各种弹出层掉用各种函数特别方便,特别简单,特别好用. 引入只需要引入这两个,css都不需要, ...
- POJ 2181 贪心
思路: 贪心 对于每个波浪 ans+=最大值-最小值 注意最后一定是选最大值 //By SiriusRen #include <cstdio> using namespace std; i ...
- HDU 2633 Getting Driving License(模拟)
Getting Driving License Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- vue2.0 transition用法
html: <div id="demo"> <button v-on:click="show = !show"> Toggle < ...
- python hmac 加密
python2 : key 是秘钥 类型为 str msg 要加密的文件 str digestmod 要加密的方式 python3: key 是秘钥 类型为 byte msg 要加密的文件 byte ...
- 【Python学习】爬虫报错处理bs4.FeatureNotFound
[BUG回顾] 在学习Python爬虫时,运Pycharm中的文件出现了这样的报错: bs4.FeatureNotFound: Couldn’t find a tree builder with th ...
- python之-字符编码
1.内存和硬盘都是用来存储的. CPU:速度快 硬盘:永久保存 2.文本编辑器存取文件的原理(nodepad++,pycharm,word) 打开编辑器就可以启动一个进程,是在内存中的,所以在编辑器编 ...
- sql%rowcount 返回影响行数
oracle中.返回影响行数是:If sql%rowcount 举例: update ut_calenderStatus t set t.calenderstatus=pi_flg, t.m=pi_M ...
- 在OSG 实现的 oculus rift 效果
在OSG 实现的oculus rift 效果,还不错 这个是Delta3d中实现的 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh1eWluZ3Fpb ...