POJ 2570Fiber Network(Floyd+位运算)
来源:互联网 发布:917自动发卡源码 编辑:程序博客网 时间:2024/04/29 08:42
都知道位运算对于集合的交并运算灰常简单。
这道题要找到所有能从点u到点v的公司,那么我们如果有一个中间点k的话,从u到k的公司属于一个集合,从k到v的公司又属于一个集合,那么我们就会用到集合的取交集运算,所以这里我们使用的位运算。
具体实现看代码。
#pragma warning(disable:4996)#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 205;int mp[N][N];int main() {int n;while (scanf("%d", &n)) {if (n == 0)break;memset(mp, 0, sizeof mp);int u, v;char ch[30];while (scanf("%d %d", &u, &v)) {if (u == 0 && v == 0)break;scanf("%s", ch);int len = strlen(ch);for (int i = 0; i < len; i++) {int tmp = (int)(ch[i] - 'a');mp[u][v] = (mp[u][v] | (1 << tmp));}}for (int k = 1; k <= n; k++) {for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {mp[i][j] |= (mp[i][k] & mp[k][j]);}}}while (scanf("%d %d", &u, &v)) {if (u == 0 && v == 0)break;if (mp[u][v] == 0) printf("-\n");else {int tmp = mp[u][v], cnt = 0;while (tmp) {if (tmp & 1) {printf("%c", 'a' + cnt);}tmp >>= 1;cnt++;}printf("\n");}}printf("\n");}return 0;}
0 0
- POJ--2570--Fiber Network【floyd+位运算】
- POJ 2570Fiber Network(Floyd+位运算)
- [floyd]poj 2570 fiber network #floyd+位运算
- poj 2570 Fiber Network(传递闭包,floyd+位运算)
- poj 2570 Fiber Network (Floyd)
- poj 2570 Fiber Network Floyd
- poj 2570 Fiber Network(floyd)
- zoj 1967 Fiber Network(位运算&&FLOYD)
- poj 2570 Fiber Network --floyd求传递闭包加位运算
- poj 2570 Fiber Network(floyd)
- poj 2570 Fiber Network(最短路+Floyd)
- poj 2570 Fiber Network floyd算法
- Poj 2570 Fiber Network【Floyd+状态压缩】
- POJ 2570 Fiber Network(floyd闭包)
- poj 2570 Fiber Network (两种解法 1.floyd+位操作 2.传递闭包)
- POJ 2570 Fiber Network(Floyd传递闭包+状态压缩)
- poj 2570 Fiber Network Floyd思想+二进制处理
- POJ 2570 Fiber Network
- Jedis实现Publish/Subscribe功能
- Redis数据过期策略探究
- vs中release版本程序崩溃的重要原因
- java树状显示文件名
- 文字中间划线
- POJ 2570Fiber Network(Floyd+位运算)
- apache 安装
- 登录的大屏背景
- Android笔记之Activity生命周期实测
- =使用原生的CIFilter创建二维码
- 实战Linux设备驱动--万事开头难--HelloWorld
- 工作常用工具命令
- [MySQL FAQ]系列 — 从MyISAM转到InnoDB需要注意什么
- 解决隐藏NavigationBar后跳转界面闪现小黑块的问题