博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2263&& zoj1952 floyd
阅读量:6583 次
发布时间:2019-06-24

本文共 3095 字,大约阅读时间需要 10 分钟。

Fiber Network
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2725   Accepted: 1252

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.

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.

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-
 
这也是一道典型的floyd。这个题有意思的地方在于对于输入数据的处理,这个是关键,其他的其实非常简单,笔者比较愚蠢,这个处理搞了半天才搞懂。
下面是代码:
 
#include 
#include
#include
#include
using namespace std;int m[201][201];//floyd中的矩阵int n;int i,j,k;//循环变量void floyd(){//模板 for(k=1;k<=n;++k) for(i=1;i<=n;++i) for(j=1;j<=n;++j) { m[i][j]=m[i][j]|(m[i][k]&m[k][j]);//这里是这道题目的关键,这里要求不是最短的路径,而且是要求有哪些点可以满足条件,所以要进行变式 }}int main(){ int A,B; char str[100]; char ch; while(scanf("%d",&n) && n){ memset(m,0,sizeof(m)); while(scanf("%d%d",&A,&B)){ if(A==0&&B==0) break; scanf("%s",str); for(i=0;str[i];++i) m[A][B]=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<
 

转载地址:http://lkxno.baihongyu.com/

你可能感兴趣的文章
TDD: 解除依赖
查看>>
L3-003. 社交集群
查看>>
【风马一族_git_github】git的工作流程
查看>>
fiddler4使用教程
查看>>
SUSE linux使用zypper 安装软件-比yum更好用
查看>>
UUID为36位
查看>>
程序员的经验
查看>>
CodeForces-1167E-Range Deleting
查看>>
兼容多个版本程序集的web.config配置
查看>>
JS 之如何在插入元素时插在原有元素的前面而不是末尾
查看>>
vim编辑器-多行加注释与去注释
查看>>
CodeForces 197A Plate Game :轮流在矩形中放圆,先放不下者输 :博弈+思维
查看>>
java finally块执行时机分析
查看>>
小强的HTML5移动开发之路(35)——jQuery中的过滤器详解
查看>>
string中c_str()、data()、copy(p,n)函数的用法+strstr()函数用法
查看>>
Linux里的lsb_release命令用来查看当前系统的发行版信 息
查看>>
spring.http.multipart.maxFileSize提示无效报错问题处理
查看>>
Docker | 删除 image 失败的一种情况
查看>>
hibernate框架内容整理 学习
查看>>
day6 字符串
查看>>