Uva - 1572 - Self-Assembly
来源:互联网 发布:photoshop加密软件 编辑:程序博客网 时间:2024/05/21 15:04
把A+~Z+,A-~Z-看成52个点,正方形看成边,就得到一个有向图,当存在有向图的时候有解。和10129有点像,做拓扑排序即可。
吐槽:刚开始把循环输入用cin,读取字符串用了scanf,直接WA了,要用还是用成一致的都cin,或者都scanf,这样就没问题了。
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cctype>#include <cstring>#include <string>#include <sstream>#include <vector>#include <set>#include <map>#include <algorithm>#include <stack>#include <queue>#include <bitset> #include <cassert> using namespace std;const int maxn = 52;int G[maxn][maxn];// 把52种字符A+~Z+,A-~Z-,转化成数字int ID(char a1, char a2){return (a1 - 'A') * 2 + ((a2 == '+') ? 0 : 1);}void connect(char a1, char a2, char b1, char b2){if (a1 == '0' || b1 == '0') { // 有00边不能连接return;}int u = ID(a1, a2) ^ 1;int v = ID(b1, b2);G[u][v] = 1;}int c[maxn]; // 表示访问状态// 判断是否从u出发存在有向环bool dfs(int u){c[u] = -1; // 表示正在访问for (int v = 0; v < maxn; v++) {if (G[u][v]) {if (c[v] < 0) { //走到起点了return true;}else if (!c[v] && dfs(v)) {return true;}}}c[u] = 1;return false;}// 是否存在有向环bool findCycle(){memset(c, 0, sizeof(c));for (int i = 0; i < maxn; i++) {if (!c[i]) {if (dfs(i)) {return true;}}}return false;}int main(){ios::sync_with_stdio(false);int n;//while (scanf("%d", &n) == 1 && n) {while (cin >> n && n) {memset(G, 0, sizeof(G));while (n--) {char s[10];//scanf("%s", s);cin >> s;for (int i = 0; i < 4; i++) {for (int j = 0; j < 4; j++) {if (i != j) {connect(s[i * 2], s[i * 2 + 1], s[j * 2], s[j * 2 + 1]);}}}}if (findCycle()) {printf("unbounded\n");}else {printf("bounded\n");}}return 0;}
0 0
- Uva - 1572 - Self-Assembly
- UVA 1572 Self-Assembly
- uva 1572 Self-Assembly
- UVA 1572 Self-Assembly
- UVa 1572 - Self-Assembly(拓扑排序)
- UVA 1572 Self-Assembly 拓扑排序
- 自组合(Self-Assembly,UVa 1572)
- uva 1572 self-assembly ——yhx
- uva 1572 self-assembly ——yhx
- UVA 1572Self-Assembly(拓扑排序)
- [UVa 1572] 自组合(Self-Assembly)
- uvalive 6393(uva 1572) Self-Assembly 拓扑排序
- UVa 1572 - Self-Assembly <图论模型+拓扑排序>
- 例题6-19 UVA 1572 Self-Assembly自组合
- 1572 Self-Assembly
- 1572 Self-Assembly
- UVa Self-Assembly(topo sort)[待AC]
- 例题6-19 自组合(Self-Assembly, ACM/ICPC World Finals 2013, UVa 1572)
- 大型网站架构改进历程:存储的瓶颈
- Android之属性动画(一)
- 指数哥伦布码
- 出色的展厅设计为企业形象增光添彩
- mysql导入sql数据库提示。您可能正在上传很大的文件,请参考文档来寻找解决方法
- Uva - 1572 - Self-Assembly
- eclipse插件explorer安装使用
- block 中循环引用的问题
- Android out of memory 彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题
- 原型设计工具
- 多线程06-(sdwebimage 总结3)
- 面试总结
- IPV6
- Core Java 笔记(三) - 反射