poj 2263&& zoj1952 floyd
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2725 | Accepted: 1252 |
Description
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
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
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
-
这也是一道典型的floyd。这个题有意思的地方在于对于输入数据的处理,这个是关键,其他的其实非常简单,笔者比较愚蠢,这个处理搞了半天才搞懂。
下面是代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> 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<<ch-'a'))
putchar(ch);
}
if(!m[A][B])
putchar('-');
printf("\n");
}
printf("\n");
}
return 0;
}
poj 2263&& zoj1952 floyd的更多相关文章
- PoJ(2263),Floyd,最小值中的最大值
题目链接:http://poj.org/problem?id=2263 题意:题中给出相连通不同城市之间的载货量,要求找到一条从指定起点到终点的路径,并满足载货量最大. #include <io ...
- Heavy Cargo POJ 2263 (Floyd传递闭包)
Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lat ...
- POJ 2263 Heavy Cargo(Floyd + map)
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3768 Accepted: 2013 Descr ...
- POJ 2240Arbitrage(Floyd)
E - Arbitrage Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submi ...
- Poj(1125),Floyd,
题目链接:http://poj.org/problem?id=1125 多源点最短路中的,最长路的,最短路. 看到这里就懵逼了,解释一下,找到一个源点,使得路最短,(遍历源点),路最短怎么求呢? 就是 ...
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- Poj(3615),Floyd,最大值中的最小值
题目链接:http://poj.org/problem?id=3615 题意:大致题意:有N个木桩,和M个木桩对之间的高度差(从x跳到y需要往上跳的高度).从x跳跃到y的路径消耗的体力值是路径中的一个 ...
- POJ 2253 Frogger floyd算法
题目:click here 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任意两坐标间是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中 ...
- Cow Contest POJ - 3660 (floyd 传递闭包)
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...
随机推荐
- JavaScript之转义字符
<html lang="en"> <head> <meta charset="UTF-8"> <meta na ...
- firebug如何使用
1.怎么安装firebug: a.打开火狐浏览器--------b.点击火狐浏览器的右上角这个小图标-------c.点击<获取附件组件>,在右上角的搜索框()内,输入firebug,点击 ...
- github--新手使用错误分析
先上去github 或者任意托管的网站.注册账号,新建仓库, 在本地运行Xcode 新建工程,新建工程的时候 勾上本地 的仓库,然后 在本地的项目根目录执行下边的命令: git remote add ...
- ios 刷新BUG
UItextView edited = yes ; 导致 刷新奇怪: 有些方法不要自己调用: 可能会破坏组件自己的生命周期: 建议模块化开发组件,自己处理自己的事:
- Pro/Engineer wildfire 5.0 野火版系列下载及安装方法
三.PTC Pro/Engineer wildfire 5.0 M030 野火版最新版 DVD 下载(多国语言) 1.野火下载站下载32&64位下载:[32位] http://down.pro ...
- 黑马程序员_<<StringBuffer,包装类>>
--------------------ASP.Net+Android+IOS开发..Net培训.期待与您交流! -------------------- 1. StringBuffer 1.概述 S ...
- swig include使用方法
{% block content2 %} {% include "footer.html" %} {% endblock %} include语句必须放到 block模块中,不然不 ...
- Android应用开发基础篇(14)-----自定义标题栏
一.概述 每一个应用程序默认的标题栏(注意与状态栏的区别)只有一行文字(新建工程时的名字),而且颜色.大小等都是固定的,给人的感觉比较单调.但当程序需要美化的时候,那么修改标题栏是就是其中一项内容,虽 ...
- protobuf 中的嵌套消息的使用
protobuf的简单的使用,不过还留下了一个问题,那就是之前主要介绍的都是对简单数据的赋值,简单数据直接采用set_xx()即可,但是如果不是简单变量而是自定义的复合类型变量,就没有简单的set函数 ...
- 读书笔记 SQL 事务理解
事务的ACID属性 Atomicity 原子性 每个事务作为原子单元工作(即不可以再拆分),也就是说所有数据库变动事务,要么成功要么不成功. SQL Server把每个DML或者 DDL命令都当做一个 ...