Nyoj Fire Station

本文介绍了一种通过算法确定新建消防站最佳位置的方法,旨在减少城市中各居民区到最近消防站的距离。采用图论中的最短路径算法,如SPFA和Floyd算法,来解决该问题,并提供了详细的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

描述A city is served by a number of fire stations. Some residents have complained that the distance from their houses to the nearest station is too far, so a new station is to be built. You are to choose the location of the fire station so as to reduce the distance to the nearest station from the houses of the disgruntled residents. 

The city has up to 500 intersections, connected by road segments of various lengths. No more than 20 road segments intersect at a given intersection. The location of houses and firestations alike are considered to be at intersections (the travel distance from the intersection to the actual building can be discounted). Furthermore, we assume that there is at least one house associated with every intersection. There may be more than one firestation per intersection.

 
 
输入
The first line of input contains two positive integers: f,the number of existing fire stations (f <= 100) and i, the number of intersections (i <= 500). The intersections are numbered from 1 to i consecutively. f lines follow; each contains the intersection number at which an existing fire station is found. A number of lines follow, each containing three positive integers: the number of an intersection, the number of a different intersection, and the length of the road segment connecting the intersections. All road segments are two-way (at least as far as fire engines are concerned), and there will exist a route between any pair of intersections.

Subsequent test cases are separated with a single blank line.

The number of test cases are less than 200.
输出
You are to output a single integer for each test case: the lowest intersection number at which a new fire station should be built so as to minimize the maximum distance from any intersection to the nearest fire station.
样例输入
1 6
2
1 2 10
2 3 10
3 4 10
4 5 10
5 6 10
6 1 10
样例输出
5
来源
University of Waterloo Local Contest 199
上传者
张云聪

 

无奈...自己的程序POJ可以过....理工的过不去...POJ(可以用Floyd...水过)

 

标程代码:

 1  
 2 #include <iostream>
 3 #include <stdio.h>
 4 #include <string.h>
 5 #include <queue>
 6 using namespace std;
 7 #define maxN 510
 8 #define MAX 0x0fffffff
 9 int max(int x,int y){return x>y?x:y;}
10 struct point{
11     int v,nex,w;
12 }po[maxN*maxN];
13 int num,N,M,head[maxN],disY[maxN],disX[maxN],key[maxN],flag[maxN];
14 bool vis[maxN];
15 void insert(int u,int v,int w)
16 {
17     po[num].v=v;
18     po[num].w=w;
19     po[num].nex=head[u];
20     head[u]=num++;
21 }
22 void spfa(int soure,int* dis)
23 {
24     memset(vis,false,sizeof(vis));
25     queue<int>q;
26     q.push(soure);
27     vis[soure]=true;dis[soure]=0;
28     while(!q.empty())
29     {
30         int u=q.front();q.pop();vis[u]=false;
31         for(int i=head[u];i!=-1;i=po[i].nex)
32             if(dis[po[i].v]>dis[u]+po[i].w){
33                 dis[po[i].v]=dis[u]+po[i].w;
34                 if(!vis[po[i].v]){
35                     q.push(po[i].v);
36                     vis[po[i].v]=true;
37                 }
38             }
39     }
40 }
41 int main()
42 {
43     //freopen("1.txt","r",stdin);
44     char s[30];
45     while(~scanf("%d%d",&M,&N))
46     {
47         getchar();
48         int i,j,u,v,w,k=1,minn=MAX;
49         num=0;
50         memset(head,-1,sizeof(head));
51         memset(flag,0,sizeof(flag));
52         for(i=1;i<=M;i++){scanf("%d",&key[i]);getchar();}
53         if(N==1){printf("1\n");continue;}
54         while(gets(s)!=NULL&&strlen(s)){sscanf(s,"%d%d%d",&u,&v,&w);insert(u,v,w);insert(v,u,w);}
55         for(i=0;i<=N;i++)disX[i]=MAX;
56         for(i=1;i<=M;i++)spfa(key[i],disX);               
57         for(j=1;j<=N;j++){
58             int maxx=0;                           
59             if(disX[j]==0)continue;
60             for(i=1;i<=N;i++)disY[i]=disX[i];
61             spfa(j,disY);
62             for(i=1;i<=N;i++)maxx=max(maxx,disY[i]);
63             if(minn>maxx||maxx==0){k=j;minn=maxx;}                
64         }
65         printf("%d\n",k);
66     }
67 }        

 

 

POJ:

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<cstring>
 5 using namespace std;
 6 #define maxn 501
 7 #define INF 0x3f3f3f3f
 8 int n,m,cost[maxn][maxn],dis[maxn],vis[maxn];
 9 int main()
10 {
11     while(~scanf("%d%d",&m,&n))
12     {
13         int u,v,c;
14         for(int i=1;i<=n;i++)
15         {
16             dis[i]=INF;vis[i]=0;
17             for(int j=1;j<=n;j++)
18                 cost[i][j]=i==j?0:INF;
19         }
20         for(int i=1;i<=m;i++)
21         {
22             scanf("%d",&u);
23             dis[u]=0;
24             vis[u]=1;
25         }
26         while(~scanf("%d%d%d",&u,&v,&c))
27             cost[u][v]=cost[v][u]=c;
28         for(int k=1;k<=n;k++)
29             for(int i=1;i<=n;i++)   
30                 for(int j=1;j<=n;j++)   
31                     cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
32         for(int i=1;i<=n;i++)
33             if(vis[i])
34                 for(int j=1;j<=n;j++)
35                     dis[j]=min(dis[j],cost[i][j]);
36         int ans=INF,pos;
37         for(int i=1;i<=n;i++)
38         {
39             int temp=-1;
40             for(int j=1;j<=n;j++)
41                 temp=max(temp,min(dis[j],cost[i][j]));
42             if(ans>temp)ans=temp,pos=i;
43         }
44         printf("%d\n",pos);
45     }
46     return 0;
47 }
View Code

 

转载于:https://www.cnblogs.com/wangmengmeng/p/5367819.html

内容概要:该PPT详细介绍了企业架构设计的方法论,涵盖业务架构、数据架构、应用架构和技术架构四大核心模块。首先分析了企业架构现状,包括业务、数据、应用和技术四大架构的内容和关系,明确了企业架构设计的重要性。接着,阐述了新版企业架构总体框架(CSG-EAF 2.0)的形成过程,强调其融合了传统架构设计(TOGAF)和领域驱动设计(DDD)的优势,以适应数字化转型需求。业务架构部分通过梳理企业级和专业级价值流,细化业务能力、流程和对象,确保业务战略的有效落地。数据架构部分则遵循五大原则,确保数据的准确、一致和高效使用。应用架构方面,提出了分层解耦和服务化的设计原则,以提高灵活性和响应速度。最后,技术架构部分围绕技术框架、组件、平台和部署节点进行了详细设计,确保技术架构的稳定性和扩展性。 适合人群:适用于具有一定企业架构设计经验的IT架构师、项目经理和业务分析师,特别是那些希望深入了解如何将企业架构设计与数字化转型相结合的专业人士。 使用场景及目标:①帮助企业和组织梳理业务流程,优化业务能力,实现战略目标;②指导数据管理和应用开发,确保数据的一致性和应用的高效性;③为技术选型和系统部署提供科学依据,确保技术架构的稳定性和扩展性。 阅读建议:此资源内容详尽,涵盖企业架构设计的各个方面。建议读者在学习过程中,结合实际案例进行理解和实践,重点关注各架构模块之间的关联和协同,以便更好地应用于实际工作中。
资 源 简 介 独立分量分析(Independent Component Analysis,简称ICA)是近二十年来逐渐发展起来的一种盲信号分离方法。它是一种统计方法,其目的是从由传感器收集到的混合信号中分离相互独立的源信号,使得这些分离出来的源信号之间尽可能独立。它在语音识别、电信和医学信号处理等信号处理方面有着广泛的应用,目前已成为盲信号处理,人工神经网络等研究领域中的一个研究热点。本文简要的阐述了ICA的发展、应用和现状,详细地论述了ICA的原理及实现过程,系统地介绍了目前几种主要ICA算法以及它们之间的内在联系, 详 情 说 明 独立分量分析(Independent Component Analysis,简称ICA)是近二十年来逐渐发展起来的一种盲信号分离方法。它是一种统计方法,其目的是从由传感器收集到的混合信号中分离相互独立的源信号,使得这些分离出来的源信号之间尽可能独立。它在语音识别、电信和医学信号处理等信号处理方面有着广泛的应用,目前已成为盲信号处理,人工神经网络等研究领域中的一个研究热点。 本文简要的阐述了ICA的发展、应用和现状,详细地论述了ICA的原理及实现过程,系统地介绍了目前几种主要ICA算法以及它们之间的内在联系,在此基础上重点分析了一种快速ICA实现算法一FastICA。物质的非线性荧光谱信号可以看成是由多个相互独立的源信号组合成的混合信号,而这些独立的源信号可以看成是光谱的特征信号。为了更好的了解光谱信号的特征,本文利用独立分量分析的思想和方法,提出了利用FastICA算法提取光谱信号的特征的方案,并进行了详细的仿真实验。 此外,我们还进行了进一步的研究,探索了其他可能的ICA应用领域,如音乐信号处理、图像处理以及金融数据分析等。通过在这些领域中的实验和应用,我们发现ICA在提取信号特征、降噪和信号分离等方面具有广泛的潜力和应用前景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值