1072 Gas Station (30 分)(最短路径)

#include<bits/stdc++.h> using namespace std;
const int N=1e3+;
int n,m,k,Ds;
int mp[N][N];
int dis[N];
int vis[N];
int inf=0x3f3f3f3f;
int toint(char s[])
{
int sum=;
int len=strlen(s);
for(int i=;i<len;i++){
if(s[i]=='G') continue;
sum=sum*+s[i]-'';
}
if(s[]=='G') return sum+n;
return sum;
} void Dijkstra(int v)
{
fill(vis,vis+N,false);
fill(dis,dis+N,inf);
for(int i=;i<=n+m;i++){
dis[i]=mp[v][i];
}
dis[v]=;
for(int i=;i<n+m;i++){
int u=-;
int minn=inf;
for(int j=;j<=n+m;j++){
if(!vis[j]&&minn>dis[j]){
u=j;
minn=dis[j];
}
}
vis[u]=true;
for(int j=;j<=n+m;j++){
if(!vis[j]&&dis[j]>mp[u][j]+dis[u]){
dis[j]=mp[u][j]+dis[u];
}
}
}
}
int main()
{
scanf("%d %d %d %d",&n,&m,&k,&Ds);
fill(mp[],mp[]+N*N,inf);
for(int i=;i<k;i++){
char s1[],s2[];
int num;
scanf("%s %s %d",s1,s2,&num);
int a=toint(s1);
int b=toint(s2);
mp[a][b]=mp[b][a]=num;
}
int id=-;
double maxDis=-;
double minAvg=inf;
for(int i=n+;i<=n+m;i++){
Dijkstra(i);
double avg=;
double Min=inf;
bool flag=false;
for(int j=;j<=n;j++){
if(dis[j]>Ds){
flag=true;
break;
}
if(Min>dis[j]){
Min=dis[j];
}
avg+=1.0*dis[j]/n;
}
if(flag) continue;
if(maxDis<Min){
maxDis=Min;
id=i;
minAvg=avg;
}
else if(maxDis==Min&&minAvg>avg){
id=i;
minAvg=avg;
} }
if(id==-) printf("No Solution\n");
else{
printf("G%d\n",id-n);
printf("%.1f %.1f\n",maxDis,minAvg);
}
return ;
}
1072 Gas Station (30 分)(最短路径)的更多相关文章
- PAT 甲级 1072 Gas Station (30 分)(dijstra)
1072 Gas Station (30 分) A gas station has to be built at such a location that the minimum distance ...
- 【PAT甲级】1072 Gas Station (30 分)(Dijkstra)
题意: 输入四个正整数N,M,K,D(N<=1000,M<=10,K<=10000)分别表示房屋个数,加油站个数,路径条数和加油站最远服务距离,接着输入K行每行包括一条路的两条边和距 ...
- pat 甲级 1072. Gas Station (30)
1072. Gas Station (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A gas sta ...
- 1072. Gas Station (30)【最短路dijkstra】——PAT (Advanced Level) Practise
题目信息 1072. Gas Station (30) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B A gas station has to be built at s ...
- 1072 Gas Station (30)(30 分)
A gas station has to be built at such a location that the minimum distance between the station and a ...
- PAT Advanced 1072 Gas Station (30) [Dijkstra算法]
题目 A gas station has to be built at such a location that the minimum distance between the station an ...
- PAT 1072. Gas Station (30)
A gas station has to be built at such a location that the minimum distance between the station and a ...
- 1072. Gas Station (30)
先要求出各个加油站 最短的 与任意一房屋之间的 距离D,再在这些加油站中选出最长的D的加油站 ,该加油站 为 最优选项 (坑爹啊!).如果相同D相同 则 选离各个房屋平均距离小的,如果还是 相同,则 ...
- 1072. Gas Station (30) 多源最短路
A gas station has to be built at such a location that the minimum distance between the station and a ...
- PAT甲题题解-1072. Gas Station (30)-dijkstra最短路
题意:从m个加油站里面选取1个站点,使得其离住宅的最近距离mindis尽可能地远,并且离所有住宅的距离都在服务范围ds之内.如果有很多相同mindis的加油站,输出距所有住宅平均距离最小的那个.如果平 ...
随机推荐
- 【luogu P2880 [USACO07JAN]平衡的阵容Balanced Lineup】 题解
题目链接:https://www.luogu.org/problemnew/show/P2880 是你逼我用ST表的啊qaq #include <cstdio> #include < ...
- 【luogu P2731 骑马修栅栏】 题解
题目链接:https://www.luogu.org/problemnew/show/P2731 这个题是欧拉回路的模板题,那么在这里给出一个hierholzer的做法. 对于求欧拉回路的问题,有Fl ...
- [译]GLUT教程 - 安装
Lighthouse3d.com >> GLUT Tutorial >> Basics >> Setup 你需要什么 要用GLUT库开发程序,你可以下载最新版本3. ...
- RPC的应用(The lowest layer of RPC)
server端代码: #include <stdio.h>#include <rpc/rpc.h>#include <rpcsvc/rusers.h> void n ...
- JavaScript函数-高阶函数
JavaScript的函数其实都指向某个变量.既然变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数. function add(x,y,f) ...
- 使用xlsx把json对象导出excel
1,首先使用npm下载xlsx.执行命令 npm install xlsx --save import { Component, OnInit } from '@angular/core'; //im ...
- About Unity3D 4.1.2 (to continue…)
Here are something that need to take care of when you work with Unity3D: 1) It seems Unity3D could c ...
- 实践笔记-VA05 销售订单清单 增加字段
现在都自开发很多报表 ,估计没有多少人 用 VA05 1.在结构 VBMTVZ 中增加需要的字段 2.表t180a 中 添加一条 “添加字段”的数据,如下: 3.取值 修改程序 INCLUDE V ...
- PostgreSQL数据库的安装
1 总体规划 操作系统 CentOS Linux release 7.5.1804 处理器 1 内存 4G 硬盘 38G 主机名称 chenzx IP地址 192.168.56.8 1.1 用户组和用 ...
- JavaScript文本框焦点事件
效果图如下: <!-- 当文本框获得焦点时候,如果文本框内容是 请输入搜索关键字 清空文本框,输入内容变黑色 --> <!-- 当文本框失去焦点时候,如果文本框无内容,则添加灰色的 ...