1072. Gas Station (30) 多源最短路
A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible.
考试的时候这句话意思没有完全理解,悲剧鸟。。。
其实就是让你找一个加油站,它到所有房子最短距离为len , 找一个加油站len的距离越大越好
加油站最多10个,以这几个加油站为原点,做dijk最短路即可
#include<stdio.h> int map[][];
const int MAX=; int use[];
int dis[];
int n,m,k,ds;
void djik(int start){
int i,j,end=n+m;
for(i=;i<=end;i++){
use[i]=;
dis[i]=MAX;
}dis[start]=; for(i=;i<=end;i++){
int min=MAX,rj;
for(j=;j<=end;j++){
if(use[j]==)continue;
if(dis[j]<min){
min=dis[j];
rj=j;
}
}use[rj]=; for(j=;j<=end;j++){ if(dis[j]>dis[rj]+map[rj][j])
dis[j]=dis[rj]+map[rj][j];
}
} for(i=;i<=end;i++){
if(start!=i)
map[start][i]=dis[i];
}
} int main()
{ while(scanf("%d%d%d%d",&n,&m,&k,&ds)!=EOF){
int i,j,end,x,ri;
end=n+m; for(i=;i<=end;i++){
for(j=;j<=end;j++)map[i][j]=MAX;
}
char ss[],ss2[];
int ll,rr,v;
for(i=;i<=k;i++){
scanf("%s",ss);
scanf("%s",ss2);
scanf("%d",&v);
if(ss[]=='G'){
if(ss[]==){
ll=ss[]-''+n;
}else if(ss[]==){
ll=ss[]-''+n;
}else{
ll=+n;
}
}else{
sscanf(ss,"%d",&ll);
} if(ss2[]=='G'){
if(ss2[]==){
rr=ss2[]-''+n;
}else if(ss2[]==){
rr=ss2[]-''+n;
}else{
rr=+n;
}
}else{
sscanf(ss2,"%d",&rr);
} map[ll][rr]=map[rr][ll]=v;
} for(i=n+;i<=end;i++){
djik(i);
} /* for(x=1;x<=end;x++){
for(i=1;i<=end;i++){
for(j=1;j<=end;j++){
if(map[i][x]+map[x][j]<map[i][j])
map[i][j]=map[i][x]+map[x][j];
}
}
}*/ int tempall,all,min=,fail=;
for(i=n+;i<=end;i++){
tempall=;
int tempmin=MAX;
int ok=;
for(j=;j<=n;j++){
if(i==j)continue;
if(map[i][j]>ds)
ok=;
if(ok==)break;
tempall+=map[i][j]; if(tempmin>map[i][j])
tempmin=map[i][j];
}
if(ok==){
fail++;
continue;
} if(tempmin==min){
if(tempall<all){
ri=i;
all=tempall;
}
}
if(tempmin>min){
min=tempmin;
ri=i;
all=tempall;
} // printf("G%
//d\n",ri-n);
// printf("%.1lf %.1lf\n",min*1.0,all*1.0/n);
} if(fail==m){
printf("No Solution\n");
}else{
printf("G%d\n",ri-n);
printf("%.1lf %.1lf\n",min*1.0,all*1.0/n);
}
}
return ;
}
1072. Gas Station (30) 多源最短路的更多相关文章
- 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 ...
- pat 甲级 1072. Gas Station (30)
1072. Gas Station (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A gas sta ...
- 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)
A gas station has to be built at such a location that the minimum distance between the station and a ...
- 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 ...
- 1072. Gas Station (30)
先要求出各个加油站 最短的 与任意一房屋之间的 距离D,再在这些加油站中选出最长的D的加油站 ,该加油站 为 最优选项 (坑爹啊!).如果相同D相同 则 选离各个房屋平均距离小的,如果还是 相同,则 ...
- 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)-dijkstra最短路
题意:从m个加油站里面选取1个站点,使得其离住宅的最近距离mindis尽可能地远,并且离所有住宅的距离都在服务范围ds之内.如果有很多相同mindis的加油站,输出距所有住宅平均距离最小的那个.如果平 ...
- PAT (Advanced Level) 1072. Gas Station (30)
枚举一下选的位置,每次算一下就可以了. #include<cstdio> #include<cstring> #include<cmath> #include< ...
随机推荐
- python3.6环境部署文档
python3.6环境部署文档 内容 Linux部署Python3.6环境 Mac部署Python3.6环境 Window10部署Python3.6环境 Pycharm安装 1. Linux部署P ...
- yum search 不好用时
用 yum provides */ eg :yum provides */pstack
- IHTMLDocument2 TO IWebBrowser2
if(NULL != pIHTMLDocument2) { IHTMLWindow2* pIHTMLWindow2 = NULL; hr = pIHTMLDocument2->get_paren ...
- Markdown - 让网络书写变得简单
概述 宗旨 Markdown 的目标是实现「易读易写」. 可读性,无论如何,都是最重要的.一份使用 Markdown 格式撰写的文件应该可以直接以纯文本发布,并且看起来不会像是由许多标签或是格式指令所 ...
- C#运算符笔记
C# 原来也可以进行向量运算,这里解决了一个为时已久的疑惑. operator struct Vector { public double x, y, z; public Vector(double ...
- PIVOT 和 UNPIVOT 命令的SQL Server版本
I:使用 PIVOT 和 UNPIVOT 命令的SQL Server版本要求 1.数据库的最低版本要求为 SQL Server 2005 或 更高 2.必须将数据库的兼容级别设置为 90 或 更高 3 ...
- Java静态绑定和动态绑定
程序绑定的概念: 绑定指的是一个方法的调用与方法所在的类(方法主体)关联起来.对java来说,绑定分为静态绑定和动态绑定:或者叫做前期绑定和后期绑定 静态绑定(早绑定 编译器绑定): 在程序执行前方法 ...
- 實現多个checkbox單選功能(转)
<script type="text/javascript"> function check(obj) { var checkbox ...
- 前端神器!!gulp livereload实现浏览器自动刷新
首先gulp是基于Node的,所以确保你已经安装 node.js,在Nodejs官方网站下载跟自己操作系统相对应的安装包. 先说一下gulp安装流程: 1:全局安装gulp,操作为: npm inst ...
- html2canvas 截屏 兼容手机端
<template> <div> <!--<input type="button" id="btnsavaImg" valu ...