POJ 2570 Fiber Network(Floyd传递闭包+状态压缩)
来源:互联网 发布:手机破解摄像头软件 编辑:程序博客网 时间:2024/04/29 03:25
POJ 2570 Fiber Network(Floyd传递闭包+状态压缩)
http://poj.org/problem?id=2570
题意:
有一个有向图,对于有向图的每条边上有一个公司名字的集合,代表该集合内的公司能提供该边的连通服务.现在我们给你q个查询.对于每个查询a和b,你要回答有哪些公司能提供从a到b的通路服务.
分析:
又是Floyd的传递闭包思想.我们用mp[i][j]=S来表示从i到j的通路集合S中的公司能提供,那么如果我们还知道mp[j][k]=S1的话.我们能推出mp[i][k] = S&S1. 其实S的二进制形式表示公司的集合.(即公司a在S中用第0位表示)
注意:mp[i][j] |=mp[i][k]&mp[k][j]; 对于同类mp[i][j]的解,需要用|来收集。
AC代码:
#include<cstdio>#include<cstring>using namespace std;const int maxn=200+10;int mp[maxn][maxn];#define ALL (1<<26)-1int main(){ int n; while(scanf("%d",&n)==1&&n) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) mp[i][j] = i==j?ALL:0; int u,v; while(scanf("%d%d",&u,&v)==2&&u) { int val=0; char str[200]; scanf("%s",str); int len=strlen(str); for(int i=0;i<len;i++) val |= 1<<(str[i]-'a'); mp[u][v] =val; } 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)==2&&u) { if(mp[u][v]==0) printf("-\n"); else { for(int i=0;i<26;i++)if(mp[u][v]&(1<<i)) printf("%c",'a'+i); printf("\n"); } } printf("\n"); } return 0;}
0 0
- POJ 2570 Fiber Network(Floyd传递闭包+状态压缩)
- Poj 2570 Fiber Network【Floyd+状态压缩】
- poj 2570 Fiber Network(传递闭包,floyd+位运算)
- POJ 2570 Fiber Network(floyd闭包)
- POJ2570 Fiber Network floyd传递闭包
- poj 2570 Fiber Network (两种解法 1.floyd+位操作 2.传递闭包)
- POJ 2570 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 floyd算法
- [floyd]poj 2570 fiber network #floyd+位运算
- poj 2570 Fiber Network(floyd)
- POJ 2570Fiber Network(Floyd+位运算)
- poj 2570 Fiber Network Floyd思想+二进制处理
- 最大子数组
- I - Dirichlet's Theorem on Arithmetic Progressions(1.5.5)
- 暑假7月7日到7月17日任务一:电路板识别。
- sdibt 2746 二叉树的输入 (先序建树)
- Hadoop - MapReduce MRAppMaster-剖析
- POJ 2570 Fiber Network(Floyd传递闭包+状态压缩)
- H - Quicksum(1.5.3)
- 【vb数据库】--创建数据库需知
- YUI3学习 (一)
- (TopkOnJstorm)第一周工作报告(2014-07-07~2014-07-13)
- 【Linux学习】Linux文件系统3—文件操作命令
- ZOJ-1154
- POJ2393 Yogurt factory 优先队列
- 堆排序