Poj 2570 Fiber Network【Floyd+状态压缩】

Fiber Network

Time Limit: 1000MS

 

Memory Limit: 65536K

Total Submissions: 3511

 

Accepted: 1604

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

Ulm Local 2001

 

题目翻译

一些公司决定搭建一个更快的网络,称为“光纤网”。他们已经在全世界建立了许多站点,这 些站点的作用类似于路由器。不幸的是,这些公司在关于站点之间的接线问题上存在争论,这样“光纤网”项目就被迫终止了,留下的是每个公司自己在某些站点之间铺设的线路。 现在,Internet 服务供应商,当想从站点 A传送数据到站点 B,就感到困惑了,到底哪个公司 能够提供必要的连接。请帮助供应商回答他们的查询,查询所有可以提供从站点 A到站定 B的线 路连接的公司。

输入描述:

输入文件包含多个测试数据。每个测试数据第 1行为一个整数 n,代表网络中站点的个数,n = 0 代表输入结束,否则 n的范围为:1≤n≤200。站点的编号为 1, …, n。接下来列出了这些站 点之间的连接。每对连接占一行,首先是两个整数 A和B,A = B = 0 代表连接列表结束,否则 A、 B的范围为:1≤A, B≤n,表示站点 A和站点 B之间的单向连接;每行后面列出了拥有站点 A到 B之间连接的公司,公司用小写字母标识,多个公司的集合为包含小写字母的字符串。 连接列表之后,是供应商查询的列表。每个查询包含两个整数 A和B,A = B = 0 代表查询列 表结束,也代表整个测试数据结束,否则 A、B 的范围为:1≤A, B≤n,代表查询的起始和终止 站点。假定任何一对连接和查询的两个站点都不相同。

输出描述:

对测试数据中的每个查询,输出一行,为满足以下条件的所有公司的标识:这些公司可以通 过自己的线路为供应商提供从查询的起始站点到终止站点的数据通路。如果没有满足条件的公司, 则仅输出字符"-"。每个测试数据的输出之后输出一个空行。 


思路:Floyd思维,能够把所有的边都进行处理,对于这样一种情况:



map【1】【3】=ab=map【1】【2】和map【2】【3】共有的字母a+map【1】【3】字母b==ab


因为英文小写字母只有26个,我们可以用int类型的一个数值来表示这条边的边权值,比如权值为b的边值为2==0*2^0+1*2^1,再比如权值为ac的边值为:5==1*2^0+0*2^1+1*2^2。也就是所谓的状态压缩。


那么map【1】【3】应该如何求呢?我们这里涉及到一个与运算和一个或运算,

map【1】【3】=map【1】【3】|(map【1】【2】&map【2】【3】)

其中|运算:全0为0,其余为1.

其中&运算:全1为1,其余为0.


那么map【1】【2】&map【2】【3】的作用就是挑出这两条边中相同字母。

那么map【1】【3】|(map【1】【2】&map【2】【3】)的作用就是合并两条边拥有的字母。


最终:

map【j】【k】=map【j】【k】|(map【j】【i】&map【i】【k】)


AC代码:


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int map[205][205];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n==0)break;
        memset(map,0,sizeof(map));
        while(1)
        {
            int x,y;char s[50];
            scanf("%d%d",&x,&y);
            if(x==0&&y==0)break;
            scanf("%s",&s);
            x--;y--;
            int output=0;
            for(int i=0;i<strlen(s);i++)
            {
                int tmp=s[i]-'a';
                tmp=(1<<tmp);
                output+=tmp;
            }
            map[x][y]=output;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                for(int k=0;k<n;k++)
                {
                    map[j][k]=(map[j][k]|(map[j][i]&map[i][k]));
                }
            }
        }
        while(1)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            if(x==0&&y==0)break;
            x--;y--;
            int k=map[x][y];
            int cont=0;
            if(k==0)printf("-");
            while(k)
            {
                int ans=k%2;
                k/=2;
                if(ans==1)
                printf("%c",cont+'a');
                cont++;
            }
            printf("\n");
        }
        printf("\n");
    }
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园的建设目标是通过数据整合、全面共享,实现校园内教学、科研、管理、服务流程的数字化、信息化、智能化和多媒体化,以提高资源利用率和管理效率,确保校园安全。 智慧校园的建设思路包括构建统一支撑平台、建立完善管理体系、大数据辅助决策和建设校园智慧环境。通过云架构的数据中心与智慧的学习、办公环境,实现日常教学活动、资源建设情况、学业水平情况的全面统计和分析,为决策提供辅助。此外,智慧校园还涵盖了多媒体教学、智慧录播、电子图书馆、VR教室等多种教学模式,以及校园网络、智慧班牌、校园广播等教务管理功能,旨在提升教学品质和管理水平。 智慧校园的详细方案设计进一步细化了教学、教务、安防和运维等多个方面的应用。例如,在智慧教学领域,通过多媒体教学、智慧录播、电子图书馆等技术,实现教学资源的共享和教学模式的创新。在智慧教务方面,校园网络、考场监控、智慧班牌等系统为校园管理提供了便捷和高效。智慧安防系统包括视频监控、一键报警、阳光厨房等,确保校园安全。智慧运维则通过综合管理平台、设备管理、能效管理和资产管理,实现校园设施的智能化管理。 智慧校园的优势和价值体现在个性化互动的智慧教学、协同高效的校园管理、无处不在的校园学习、全面感知的校园环境和轻松便捷的校园生活等方面。通过智慧校园的建设,可以促进教育资源的均衡化,提高教育质量和管理效率,同时保障校园安全和提升师生的学习体验。 总之,智慧校园解决方案通过整合现代信息技术,如云计算、大数据、物联网和人工智能,为教育行业带来了革命性的变革。它不仅提高了教育的质量和效率,还为师生创造了一个更加安全、便捷和富有智慧的学习与生活环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值