Fiber Network
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3328   Accepted: 1532

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

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
0

Sample Output

ab
d
- z
-

Source

题意:从起点到终点找到所有边权上的相同的地方。
思路: 首先,由于边权是字母又是要求边权上的相同的地方,想到状态压缩。且具有传递性,就用Floyd.
收获:a[u][v] |= 1<<(s[i] - 'a');中的|=是存入状态。a[i][k] & a[k][j] 中的&是来判断有相同的地方。
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const double PI = acos(-1.0); const int maxn = ;
int a[maxn][maxn];
int main()
{
int n;
while(~scanf("%d", &n)&&n)
{
int u, v;
memset(a, , sizeof(a));
while(scanf("%d%d", &u, &v)&& (u+v))
{
char s[];
scanf("%s", s);
for(int i = ; i < strlen(s); i++)
a[u][v] |= <<(s[i] - 'a');
} for(int k = ; k <= n; k++)
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
a[i][j] |= a[i][k] & a[k][j]; while(scanf("%d%d", &u, &v) && (u+v))
{
for(int i = 'a'; i <= 'z'; i++)
if(a[u][v] & ( << (i-'a')))
printf("%c",i);
if(!a[u][v])
printf("%c",'-');
puts("");
}
puts("");
}
return ;
}
 

POJ 2579 Fiber Network(状态压缩+Floyd)的更多相关文章

  1. Fiber Network ZOJ 1967(Floyd+二进制状态压缩)

    Description Several startup companies have decided to build a better Internet, called the "Fibe ...

  2. POJ 2570 Fiber Network

    Description Several startup companies have decided to build a better Internet, called the "Fibe ...

  3. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  4. POJ 3691 (AC自动机+状态压缩DP)

    题目链接:  http://poj.org/problem?id=3691 题目大意:给定N个致病DNA片段以及一个最终DNA片段.问最终DNA片段最少修改多少个字符,使得不包含任一致病DNA. 解题 ...

  5. [POJ 2923] Relocation (动态规划 状态压缩)

    题目链接:http://poj.org/problem?id=2923 题目的大概意思是,有两辆车a和b,a车的最大承重为A,b车的最大承重为B.有n个家具需要从一个地方搬运到另一个地方,两辆车同时开 ...

  6. POJ 1321 棋盘问题(状态压缩DP)

    不总结的话, 同一个地方会 WA 到死 思路: 状态压缩 DP. 1. s 表示压缩状态, 若第 i 列放了棋子, 那么该列置 1, 否则该列置 0. 假如 s = 3(0x011) 那么表示棋盘的第 ...

  7. POJ 2046 Gap 搜索- 状态压缩

    题目地址: http://poj.org/problem?id=2046 一道搜索状态压缩的题目,关键是怎样hash. AC代码: #include <iostream> #include ...

  8. HDU 5418——Victor and World——————【状态压缩+floyd】

    Victor and World Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Other ...

  9. POJ 2570 Fiber Network(最短路 二进制处理)

    题目翻译 一些公司决定搭建一个更快的网络.称为"光纤网". 他们已经在全世界建立了很多网站.这 些网站的作用类似于路由器.不幸的是,这些公司在关于网站之间的接线问题上存在争论,这样 ...

随机推荐

  1. UML建模工具-火龙果软件

     官网地址:http://code.uml.com.cn/index.asp     Bridge桥梁模式    (待逆向) 桥梁模式,通过增加一个类,将抽象部分与它的实现部分分离,使它们都可以独立 ...

  2. hdu 1506 Largest Rectangle in a Histogram(单调栈)

                                                                                                       L ...

  3. hdu 4504 威威猫系列故事——篮球梦_简单dp

    题目链接 题意:你现在分数为a,对方分数为b,你比赛还有n分钟,每次进攻需要15分钟,现在你先进攻,每次进攻可以得1或2或3,对方每次进攻得一分,问超过对方分数有多少种打法 思路:因为情况太多要用__ ...

  4. 游标的使用实例(Sqlserver版本)

    游标,如果是之前给我说这个概念,我的脑子有二个想法:1.你牛:2.我不会 不会不是理由,更不是借口,于是便要学习,本人属性喜欢看代码,不喜欢看书的人,所以嘛,文字对我没有吸引力:闲话少说啊,给大家提供 ...

  5. nginx 采用https 协议通信配置

    在网络通信中,使用抓包软件可以对网络请求进行分析,并进行重放攻击,重放攻击的解决方案一般是使用一个变化的参数,例如RSA加密的时间戳,但考虑到网络传输时延,时间戳需要有一定的误差容限,这样仍然不能从根 ...

  6. hadoop备战:一台x86计算机搭建hadoop的全分布式集群

    主要的软硬件配置: x86台式机,window7  64位系统 vb虚拟机(x86的台式机至少是4G内存,才干开3台虚机) centos6.4操作系统 hadoop-1.1.2.tar.gz jdk- ...

  7. Android 打造自己的个性化应用(二):应用程序内置资源实现换肤功能

    通过应用程序内置资源实现换肤,典型的应用为QQ空间中换肤的实现. 应用场景为: 应用一般不大,且页面较少,风格相对简单,一般只用实现部分资源或者只用实现背景的更换. 此种换肤方式实现的思路: 1. 把 ...

  8. jquery渐隐轮播

    html <body> <div id="banner"> <div id="banner_bg"></div> ...

  9. 使用VS调试64位应用程序

    VS2012开始,就自带IIS Express,相比先前VS的Web调试器的弱智,和IIS的繁琐,Express简直是最佳方式啦. 本机环境是64位Win7 + 64位Oracle Client,调试 ...

  10. IBM SPSS Modeler 预测建模基础(一)

    1.搜索下载IBM SPSS Modeler 14.1 32位 及 IBM SPSS Modeler 14.1 注册文件(破解布丁): 2.下载train.csv 及 test.csv: train. ...