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) 多源最短路的更多相关文章

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

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

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

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

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

  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. 1072. Gas Station (30)

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

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

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

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

  9. PAT (Advanced Level) 1072. Gas Station (30)

    枚举一下选的位置,每次算一下就可以了. #include<cstdio> #include<cstring> #include<cmath> #include< ...

随机推荐

  1. 整合Struts2与Spring

    一.需要的JAR文件为:Spring和Struts2框架本身需要的JAR文件以及他们所依赖的JAR文件

  2. BZOJ 1026 windy数 (数位DP)

    题意 区间[A,B]上,总共有多少个不含前导零且相邻两个数字之差至少为2的正整数? 思路 状态设计非常简单,只需要pos.limit和一个前驱数pre就可以了,每次枚举当前位时判断是否与上一位相差2即 ...

  3. ts结合vue使用的感悟

    TypeScript 前端现在越来越强大,多人开发更是常见,加上各大框架都开始支持TypeScript,而谷歌和微软又更加积极,导致不得不去学习,顺道通过js来了解ts,再通过ts来了解强类型语言.一 ...

  4. [转载]Java生成Word文档

    在开发文档系统或办公系统的过程中,有时候我们需要导出word文档.在网上发现了一个用PageOffice生成word文件的功能,就将这块拿出来和大家分享. 生成word文件与我们编辑word文档本质上 ...

  5. LeetCode OJ:Search in Rotated Sorted Array(翻转排序数组的查找)

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  6. phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接

    phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接--解决方法     phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接.您应该检查配置文件中的主机.用户名和 ...

  7. spring之httpclient doget请求

    /**     * @param url        请求地址     * @param jsonString 加密后的字符串     * @return     * @throws ClientP ...

  8. SpringMVC札集(09)——拦截器

    自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...

  9. memcached asp.net

    下载文件 memcached 1.解压缩文件到e:\memcached 2.命令行输入 e:\memcached\memcached.exe -d install' 3.命令行输入 e:\memcac ...

  10. MySQL安装部署及调优

    MySQL安装 二进制安装 - mysql-5.5.49 mkdir /home/oldboy/tools -p cd /home/oldboy/tools/ rz #mysql-5.5.49-lin ...