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. 【Supervisor】Linux 后台进程管理利器

    Linux的后台进程运行有好几种方法,例如nohup,screen等,但是,如果是一个服务程序,要可靠地在后台运行,我们就需要把它做成daemon,最好还能监控进程状态,在意外结束时能自动重启. su ...

  2. iptables详解(14):iptables小结之常用套路

    不知不觉,已经总结了13篇iptables文章,这些文章中有一些需要注意的地方. 此处,我们对前文中的一些注意点进行总结,我们可以理解为对"常用套路"的总结. 记住这些套路,能让我 ...

  3. 链表实现队列C语言写法

    #include<iostream> #include<cstdio> #include<cstdlib> using namespace std; typedef ...

  4. Conky配置文件

    Conky是一个可以在linux系统中实时显示系统性能的工具,美观且十分好用,我们选择安装conky-all程序包 # set to yes if you want Conky to be forke ...

  5. 解析xml节点属性及子节点内容

    xml样例 <microNearlyThreeYearsOverdueInfo subReportType="13204" subReportTypeCost="9 ...

  6. location.host 与 location.hostname 的区别

    JavaScript 中,大多数情况下,我们不会发现 location.host 与 location.hostname 的区别,因为大多数情况下,我们的网页用的是 80 端口. 他们的区别: loc ...

  7. Java高级软件工程师面试题

    Java 软件高级工程师笔试题 [智力部分](30分) 1. 烧一根不均匀的绳要用一个小时,如何用它来判断半个小时?(5分) 两头同时烧 2. 4,4,10,10,加减乘除,怎么出24点?四个数字分别 ...

  8. Java中关于内存泄漏出现的原因以及如何避免内存泄漏

    转账自:http://blog.csdn.net/wtt945482445/article/details/52483944 Java 内存分配策略 Java 程序运行时的内存分配策略有三种,分别是静 ...

  9. No module named 'cv2'出错

    当在python 3.6里运行课程里的强化学习程序时,出现如下出错,怎么办呢? >>> = RESTART: D:\work\csdn\tensorflow\DeepLearning ...

  10. TeamTalk源码分析(十一) —— pc客户端源码分析

           --写在前面的话  在要不要写这篇文章的纠结中挣扎了好久,就我个人而已,我接触windows编程,已经六七个年头了,尤其是在我读研的三年内,基本心思都是花在学习和研究windows程序上 ...