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的加油站,输出距所有住宅平均距离最小的那个.如果平 ...
随机推荐
- AngularJS web应用程序
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 前端 new和instanceof JavaScript
new和instanceof的内部机制 new 代码例子 var Func=function(){ }; var func=new Func (); new共经过4个阶段 1.创建一个空对象 var ...
- oracle-sql脚本导出EXCEL数据
在数据库中,经常有业务人员提出需求导出数据库中的业务数据,而且是每天.每周或每月定时导出.为了方便,可将sql查询的脚本 通过下面脚本来导出EXCEL数据. 1.将查询sql脚本(AAA.sql)放到 ...
- Swift_Set详解
Swift_Set详解 点击查看源码 初始化 //初始化 fileprivate func testInit() { //空Set var set = Set<String>() prin ...
- org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field xxx exceeds its maximum permitted size of 1048576 bytes.
springboot 通过MultipartFile接受前端传过来的文件时是有文件大小限制的(springboot内置tomact的的文件传输默认为1MB),我们可以通过配置改变它的大小限制 首先在启 ...
- 转:Zookeeper客户端Curator使用详解
原文:https://www.jianshu.com/p/70151fc0ef5d Zookeeper客户端Curator使用详解 前提 最近刚好用到了zookeeper,做了一个基于SpringBo ...
- php实现redis
<?php //实例化Redis对象 $red=new Redis(); //链接redis服务 $red->connect('localhost','6379'); //具体操作 $re ...
- u-boot、kernel、root系统烧写和挂载命令命令
一.uboot 环境变量: 1. 打印环境变量:# print 2. 设置启动参数# set bootargs noinitrd init=/linuxrc console=ttySAC0,11520 ...
- python 中 pynlpir错误 Cannot Open Configure file pynlpir\Data\Configure.xml 解决
在用python做分词.数据处理的时候,想调用pynlpir库,pynlpir.open()时出现错误,更新一下授权文件还是错误, 仔细一看错误是:Cannot Open Configure file ...
- R语言绘图:词云图
使用wordcloud2绘制词云图 library(wordcloud2) findwords<-function(tf){ txt<-scan(tf,"") wl&l ...