#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 分)(最短路径)的更多相关文章

  1. 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 ...

  2. 【PAT甲级】1072 Gas Station (30 分)(Dijkstra)

    题意: 输入四个正整数N,M,K,D(N<=1000,M<=10,K<=10000)分别表示房屋个数,加油站个数,路径条数和加油站最远服务距离,接着输入K行每行包括一条路的两条边和距 ...

  3. pat 甲级 1072. Gas Station (30)

    1072. Gas Station (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A gas sta ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 1072. Gas Station (30)

    先要求出各个加油站 最短的 与任意一房屋之间的 距离D,再在这些加油站中选出最长的D的加油站 ,该加油站 为 最优选项 (坑爹啊!).如果相同D相同 则 选离各个房屋平均距离小的,如果还是 相同,则 ...

  9. 1072. Gas Station (30) 多源最短路

    A gas station has to be built at such a location that the minimum distance between the station and a ...

  10. PAT甲题题解-1072. Gas Station (30)-dijkstra最短路

    题意:从m个加油站里面选取1个站点,使得其离住宅的最近距离mindis尽可能地远,并且离所有住宅的距离都在服务范围ds之内.如果有很多相同mindis的加油站,输出距所有住宅平均距离最小的那个.如果平 ...

随机推荐

  1. HDU 1099 Lottery (求数学期望)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1099 Lottery Time Limit: 2000/1000 MS (Java/Others)   ...

  2. Git push提示pre-receive hook declined

    master:local auto@ubuntu:~/src/code/ git push Counting objects: 5, done. Delta compression using up ...

  3. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛--K-密码

    链接:https://www.nowcoder.com/acm/contest/90/K 来源:牛客网 - 1.题目描述 ZiZi登录各种账号的时候,总是会忘记密码,所以他把密码都记录在一个记事本上. ...

  4. 【模板】string中substr函数的运用

    substr有两种用法: 假设:string s = "0123456789" ;  //下标从0开始 ① string a = s.substr(5)               ...

  5. 在mac上显示网速的软件——iStat Menus 5:

    在mac上显示网速的软件——iStat Menus 5: https://bjango.com/mac/istatmenus/ 注册码: Email: 982092332@qq.com SN: GAW ...

  6. nigx配置location规则

    以下是收集的,对于不是很熟的朋友,配置转发很有帮助 1.location匹配命令和优先级: 优先级: Directives with the = prefix that match the query ...

  7. [转]不让iTunes备份到c盘

    很多人现在的C盘都是空间不大的SSD硬盘,ITUNES备份老是占越来越大的空间,不如动手把它改成其它盘好了.下面7个步骤教你转移备份. 1.需要一个小工具:Juction.exe,如果你已经是WIN7 ...

  8. Hadoop(11)-MapReduce概述和简单实操

    1.MapReduce的定义 2.MapReduce的优缺点 优点 缺点 3.MapReduce的核心思想 4.MapReduce进程 5.常用数据序列化类型 6.MapReduce的编程规范 用户编 ...

  9. 学习photoshop心得

    简要的学习了ps的三大功能p图,抠图,作图, p图主要是学了换脸这一效果,用到套索工具,把范冰冰的脸接到郭德纲身上, 首先使用套索工具把脸圈起来 然后移动到 另一个人脸上 再然后混合图层,自动混合 差 ...

  10. JAVA 反射之Method

    ★ Method没有构造器,只能通过Class获取. 重点方法: class.getDeclaredMethods():获取所有方法. class.getDeclaredMethod(String n ...