poj2570||zoj1967 floyd思想
来源:互联网 发布:知乎 自己掏耳屎的方法 编辑:程序博客网 时间:2024/06/07 09:36
Fiber Network
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2624 Accepted: 1203
Description
Several startup companies have decided to build a better Internet, called the "FiberNet". They have already installed many nodes that act as routers all around the world. Unfortunately, they started to quarrel about the connecting lines, and ended up with every company laying its own set of cables between some of the nodes.
Now, service providers, who want to send data from node A to node B are curious, which company is able to provide the necessary connections. Help the providers by answering their queries.
Now, service providers, who want to send data from node A to node B are curious, which company is able to provide the necessary connections. Help the providers by answering their queries.
Input
The input contains several test cases. Each test case starts with the number of nodes of the network n. Input is terminated by n=0. Otherwise, 1<=n<=200. Nodes have the numbers 1, ..., n. Then follows a list of connections. Every connection starts with two numbers A, B. The list of connections is terminated by A=B=0. Otherwise, 1<=A,B<=n, and they denote the start and the endpoint of the unidirectional connection, respectively. For every connection, the two nodes are followed by the companies that have a connection from node A to node B. A company is identified by a lower-case letter. The set of companies having a connection is just a word composed of lower-case letters.
After the list of connections, each test case is completed by a list of queries. Each query consists of two numbers A, B. The list (and with it the test case) is terminated by A=B=0. Otherwise, 1<=A,B<=n, and they denote the start and the endpoint of the query. You may assume that no connection and no query contains identical start and end nodes.
After the list of connections, each test case is completed by a list of queries. Each query consists of two numbers A, B. The list (and with it the test case) is terminated by A=B=0. Otherwise, 1<=A,B<=n, and they denote the start and the endpoint of the query. You may assume that no connection and no query contains identical start and end nodes.
Output
For each query in every test case generate a line containing the identifiers of all the companies, that can route data packages on their own connections from the start node to the end node of the query. If there are no companies, output "-" instead. Output a blank line after each test case.
Sample Input
31 2 abc2 3 ad1 3 b3 1 de0 01 32 13 20 021 2 z0 01 22 10 00
Sample Output
abd-z-
Source
Ulm Local 2001
题意:查询所有可以提供从站点A到站点B的路线连接的公司(a--z)
分析:本题并不是求解最短路径,但可以用到floyd算法求解最短路径的思路。具体详解参考:算法图论187
// I'm the Topcoder//C#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <math.h>#include <time.h>//C++#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <cctype>#include <stack>#include <string>#include <list>#include <queue>#include <map>#include <vector>#include <deque>#include <set>using namespace std;//*************************OUTPUT*************************#ifdef WIN32#define INT64 "%I64d"#define UINT64 "%I64u"#else#define INT64 "%lld"#define UINT64 "%llu"#endif//**************************CONSTANT***********************#define INF 0x3f3f3f3f#define eps 1e-8#define PI acos(-1.)#define PI2 asin (1.);typedef long long LL;//typedef __int64 LL; //codeforcestypedef unsigned int ui;typedef unsigned long long ui64;#define MP make_pairtypedef vector<int> VI;typedef pair<int, int> PII;#define pb push_back#define mp make_pair//***************************SENTENCE************************#define CL(a,b) memset (a, b, sizeof (a))#define sqr(a,b) sqrt ((double)(a)*(a) + (double)(b)*(b))#define sqr3(a,b,c) sqrt((double)(a)*(a) + (double)(b)*(b) + (double)(c)*(c))//****************************FUNCTION************************template <typename T> double DIS(T va, T vb) { return sqr(va.x - vb.x, va.y - vb.y); }template <class T> inline T INTEGER_LEN(T v) { int len = 1; while (v /= 10) ++len; return len; }template <typename T> inline T square(T va, T vb) { return va * va + vb * vb; }// aply for the memory of the stack//#pragma comment (linker, "/STACK:1024000000,1024000000")//end#define MAXN 200+10int m[MAXN][MAXN];//floyd的矩阵Aint n,A,B;char str[26+10];char ch;void floyd(){ for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ m[i][j]|=m[i][k]&m[k][j]; } } }}int main(){ while(scanf("%d",&n)!=EOF){ if(n==0 ) break; memset(m,0,sizeof(m)); while(scanf("%d%d",&A,&B)){ if(A==0&&B==0) break; scanf("%s",str); for(int i=0;str[i];i++){ m[A][B]|=1<<(str[i]-'a'); } } floyd(); //查询 while(scanf("%d%d",&A,&B)){ if(A==0&&B==0) break; for(ch='a';ch<='z';ch++){ //输出 if(m[A][B]&(1<<(ch-'a'))){ putchar(ch); } } if(!m[A][B]) putchar('-'); putchar('\n'); } putchar('\n'); } return 0;}
- poj2570||zoj1967 floyd思想
- poj2570 zoj1967 Fiber Network floyd
- poj2570 Floyd
- poj2263&poj2570 floyd变形
- POJ2570 二进制,位运算,Floyd
- POJ2570 Fiber Network floyd传递闭包
- poj2570&zoj1967Fiber Network(floyd+状态压缩)
- poj2570 Fiber Network 最短路floyd
- POJ2570
- 传递闭包+二进制位运算+floyd(poj2570)
- POJ 2263 floyd思想
- POJ 2253 floyd思想
- Floyd算法思想
- POJ2570:Fiber Network
- POJ - 3613 Floyd的思想+矩阵乘法
- hdu 4034 Graph解题报告-Floyd思想
- UVa10099 The Tourist Guide(Floyd思想)
- hdu 3631(floyd思想的运用)
- C语言中的空指针、空指针常量、NULL_&_0
- 用Java实现多项式相加
- 正式转战cnblogs。开始我新的代码生涯
- 学习计划
- logistic regression 学习笔记
- poj2570||zoj1967 floyd思想
- POJ 2263 floyd思想
- POJ 2253 floyd思想
- ZOJ 2797 ||POJ 2472 floyd变形
- ZOJ 1082 floyd
- ZOJ1203 kruskal求最小生成树
- POJ 1861||ZOJ1542 kruskal求最小生成树(POJ秒杀啊)
- POJ1251 || ZOJ1406 kruskal求最小生成树
- POJ1287 || ZOJ1372 kruskal