POJ 2570 传递闭包 Floyd
题意:n个点
下面边 以(0,0)输入结尾
u v 字母, 表示u v间有 xx个字母
问:
(0,0)输入结尾
问 u v间的路径 都存在的字母有哪些,输出这些字母
#include <cstdio> #include <cstring> #include <iostream> #include <math.h> #include <queue> #define N 250 #define M N*N+2 #define inf64 0x7ffffff #define inf 0x7ffffff using namespace std; inline int Min(int a,int b){return a>b?b:a;} int map[N][N]; int main() { int n,u,v; char name[30]; while(scanf("%d",&n),n){ memset(map,0,sizeof(map)); scanf("%d %d ",&u,&v); while(u!=0 && v!=0){ scanf("%s",name); for(int i=0;i<strlen(name);i++) map[u][v]|=1<<(name[i]-'a'); scanf("%d%d",&u,&v); } for (int k = 1;k <= n;k ++) //floyd for (int i = 1;i <= n;i ++) for (int j = 1;j <= n;j ++) if (map[i][k]&map[k][j]) map[i][j] = map[i][j]|(map[i][k]&map[k][j]); scanf("%d %d",&u,&v); while(u!=0 && v!=0){ if(map[u][v]){ for(int i=0;i<30;i++)if(map[u][v]&(1<<i))printf("%c",i+'a'); } else printf("-"); puts(""); scanf("%d %d",&u,&v); } puts(""); } return 0; } /* 3 1 2 abc 2 3 ad 1 3 b 3 1 de 0 0 1 3 2 1 3 2 0 0 2 1 2 z 0 0 1 2 2 1 0 0 */
补充:软件开发 , C++ ,