传递闭包+二进制位运算+floyd(poj2570)
Fiber Network
Time
Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 3125
Accepted: 1436 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 00
Sample Output
ab d-
z-
题意:给出n个点,然后给出边a,b ,str代表str中的这些字母可以保证a到b的联通,然后有多组询问u和v,问u到v可以由那些字母保证连通性,若没有输出-
分析:一共26个字母可以使用位运算,g[a][b]代表那些可以联通,用传递闭包即可 #include"stdio.h" #include"string.h" #include"stdlib.h" #include"queue" #include"algorithm" #include"string.h" #include"string" #include"math.h" #include"vector" #include"stack" #include"map" #define eps 1e-8 #define inf 0x3f3f3f3f #define M 250 using namespace std; int g[M][M],vis[M]; char str[M]; int main() { int n,i,a,b,c,j,k,kk=0; while(scanf("%d",&n),n) { memset(g,0,sizeof(g)); memset(vis,0,sizeof(vis)); while(scanf("%d%d",&a,&b),a||b) { scanf("%s",str); for(i=0;str[i]!='\0';i++) { c=str[i]-'a'; g[a][b]|=(1<<c); } } for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { g[i][j]|=(g[i][k]&g[k][j]); } } } if(kk) printf("\n"); kk++; while(scanf("%d%d",&a,&b),a||b) { int flag=0; for(i=0;i<26;i++) { if(g[a][b]&(1<<i)) { printf("%c",i+'a'); flag++; } } if(flag) printf("\n"); else printf("-\n"); } } return 0;}
传递闭包+二进制位运算+floyd(poj2570)的更多相关文章
- Japan 2005 Domestic Cleaning Robot /// BFS 状压 二进制位运算 结构体内构造函数 oj22912
题目大意: 输入w h,接下来输入h行w列的图 ' . ':干净的点: ' * ' :垃圾: ' x ' : 墙: ' o ' : 初始位置: 输出 清理掉所有垃圾的最短路径长度 无则输出-1 ...
- POJ--2570--Fiber Network【floyd+位运算】
题意:一些公司决定搭建一些光纤网络.单向的,假设从第一点到第二点,有ab两个公司能够搭建,第二点到第三点有ac两个公司能够搭建,第一点到第三点有d公司能够搭建,则第一点到第三点有a.d两个公司能够搭建 ...
- 【BZOJ2208】【JSOI2010】连通数 传递闭包
题目描述 定义一个图的连通度为图中可达顶点对的数目.给你一个\(n\)个点的有向图,问你这个图的连通度. \(n\leq 2000,m\leq n^2\) 题解 一个很简单的做法就是传递闭包:像flo ...
- 位运算 2013年山东省赛 F Alice and Bob
题目传送门 /* 题意: 求(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1) 式子中,x的p次方的系数 二进制位运算:p ...
- Bzoj 1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 传递闭包,bitset
1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 323 Solved ...
- 单词words
论一类脑筋急转弯题和奇技淫巧题的解题技巧 [题意] 给定n个长为m且只包含xyz的字符串,定义两个字符串的相似程度为它们对应位置相同字符个数(比如xyz和yyz的相似程度为2,后两位相同),分别求出相 ...
- 收集一些关于OI/ACM的奇怪的东西……
一.代码: 1.求逆元(原理貌似就是拓展欧几里得,要求MOD是素数): int inv(int a) { if(a == 1) return 1; return ((MOD - MOD / a) * ...
- Java学习总结(二)----Java语言基础
1. Java语言基础 2.1 关键字 定义:被java语言赋予特殊含义的单词 特点:关键字中的字母都为小写 用于定义数据类型的关键字 class,interface,byte,short,i ...
- Java 关键字、标识符、注释、常量与变量、数据类型,算术、赋值、比较、逻辑、位、三元运算符和流程控制、break、continue【3】
若有不正之处,请多多谅解并欢迎批评指正,不甚感激.请尊重作者劳动成果: 本文原创作者:pipi-changing本文原创出处:http://www.cnblogs.com/pipi-changing/ ...
随机推荐
- Python For Data Analysis -- NumPy
NumPy作为python科学计算的基础,为何python适合进行数学计算,除了简单易懂,容易学习 Python可以简单的调用大量的用c和fortran编写的legacy的库 Python科学计算的这 ...
- 一 mybatis快速入门
什么是MyBatis MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架. MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索. MyBatis可以使用简 ...
- 常用ARM汇编指令
常用ARM汇编指令 [日期:2012-07-14] 来源:Linux社区 作者:xuyuanfan77 [字体:大 中 小] 在嵌入式开发中,汇编程序常常用于非常关键的地方,比如系统启动时初 ...
- 利用VS编译libiconv库
参考文章:http://blog.csdn.net/ghevinn/article/details/9834119 关于中文字符编码问题,这篇文章里面讲的很详细-->http://www.tui ...
- angularJS自定义指令间的“沟通”
由此例子我们可以看出,angularJS使用指令时link的执行顺序<html> <head> <meta charset="utf-8"/> ...
- java对象中继承和变量初始化顺序浅析
先上例子代码 public class F { int age = 5; public F() { print(); } public void print() { System.out.printl ...
- animate实现动画效果
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- oracle 中的存储过程
oracle 中的存储过程 --oracle 中的存储过程, --不带任何参数的 CREATE OR REPLACE PROCEDURE PRO_TEST AS -- AS 和is 没有任何区别 ...
- 苹果公司给出的检测 advertisingIdentifier 的方法
To locate the reference to the advertisingIdentifier selector, please perform these steps to create ...
- HTML: 仿写一个财经类静态的网页
要求:仿写一个静态的网页,主要采用HTML+CSS+DIV的布局方式, 新建两个文件:demo.html.demo.css 图片素材:image.zip demo.html代码如下: <!doc ...