题目的测试用例数据有问题!

第一个Case 应该是

G1

2.0 3.2

一直在想3.3分母的3怎么来了。ORZ

#include <iostream>
#include <cctype>
#include <limits>
#include <cstdlib>
#include <string>
#include <stdio.h>
using namespace std;
int ma[1020][1020];
int num[1020];
int n,m,k,ds;
int i,j;
int INF=numeric_limits<int>::max();
int dp[1020];
int vis[1020];
// station --- house 最小距离越大越好
void djkstra(int gx){
for(i=0;i<1020;i++){
dp[i]=INF;
vis[i]=0;
}
dp[gx]=0;
for(i=1;i<=m+n;i++){
int x,mm=INF;
for(j=1;j<1020;j++){
if(num[j]!=0){
if(!vis[j]&&dp[j]<mm){
mm=dp[x=j];
}
}
}
vis[x]=1;
for(j=1;j<1020;j++){
if(num[j]!=0){
if(ma[x][j]!=0){
if(dp[x]+ma[x][j]<dp[j]){
dp[j]=dp[x]+ma[x][j];
}
}
}
}
} }
// minimum distance in service range smallest average
int main()
{
cin>>n>>m>>k>>ds;
for(i=1;i<=n;i++) num[i+10]=1;
for(i=1;i<=m;i++) num[i]=1;
for(i=0;i<k;i++){
string p1,p2;
int dist;
int a,b;
cin>>p1>>p2>>dist;
if(isdigit(p1[0])) a=atoi(p1.data())+10;
else {
a=atoi(p1.substr(1).data());
}
if(isdigit(p2[0])) b=atoi(p2.data())+10;
else {
b=atoi(p2.substr(1).data());
}
ma[a][b]=ma[b][a]=dist;
}
int disMinA=-1;
int sumDisA=0;
int inde=INF;int t;
int isInA=0;
for(t=1;t<=m;t++){
djkstra(t);
// distance is set find minimum
int isIn=1;
int disMin=INF;
int sumDis=0;
for(int p=1;p<=n;p++){
if(dp[p+10]>ds){
isIn=0;
break;
}
}
if(isIn){
isInA=1;
for(int p=1;p<=n;p++){
sumDis+=dp[p+10];
if(disMin>dp[p+10]) disMin=dp[p+10];
}
if(disMin>disMinA){
disMinA=disMin;
sumDisA=sumDis;
inde=t;
}else if(disMin==disMinA){
if(sumDis<sumDisA){
inde=t;sumDisA=sumDis;
}else if(sumDis==sumDisA){
if(inde>t) inde=t;
}
}
}
}
if(isInA){
cout<<"G"<<inde<<endl;
printf("%.1f %.1f\n",disMinA+0.0,(sumDisA+0.0)/n);
}else{
cout<<"No Solution"<<endl;
}
return 0;
}

  

PAT1072. Gas Station (30)的更多相关文章

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

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

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

  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)

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

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

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

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

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

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

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

随机推荐

  1. linux系统分析命令总结

    一张图片

  2. java基础02

    使用 myeclipse写第一个java程序 之后  右键 点击 src  创建 Class /** * package:包的声明! * 代表我们当前的java源文件在项目中的位置! * 必须位于除了 ...

  3. 【opencv】caffe 读入空图导致opencv错误

    OpenCV Error: Assertion failed (ssize.area() > ) /modules/imgproc/src/imgwarp. 根据错误提示,查看一下opencv源 ...

  4. 基于Maven的SSM框架搭建

    Maven + Spring + Spring MVC + Mybatis + MySQL整合SSM框架 1.数据库准备 本文主要想实现SSM框架的搭建,并基于该框架实现简单的登录功能,那么先新建一张 ...

  5. PHP json_encode自动转码的问题

    用PHP的json_encode处理中文的时候, 中文会被编码成类似于"\u5f20\u4e09"的格式,例如: <?php $arr = array('张三','李四'); ...

  6. intellij idea 重命名或复制一个项目(不用重启)

    Idea 内无法直接修改Explorer 里文件夹的名称,只能手动改文件夹的名称. 目前找到的最好的方法: 1)重命名一个项目 在Idea 项目关闭状态下,在 Explorer (Windows) / ...

  7. Ubuntu 16.04 源码编译安装PHP7+swoole

    备注: Ubuntu 16.04 Server 版安装过程图文详解 Ubuntu16镜像地址: 链接:https://pan.baidu.com/s/1XTVS6BdwPPmSsF-cYF6B7Q 密 ...

  8. centos6.8安装Discuz!X3.1(PHP论坛)

    1.首先搭建apache+mysql+php环境: 一.安装 MySQL 首先来进行 MySQL 的安装.打开超级终端,输入: [root@localhost ~]# yum install mysq ...

  9. 自定义admin管理工具(stark组件)

    自定义admin管理工具(stark组件) 创建项目 了解了admin的功能后,我们可以开始仿照admin编写我们自己的管理工具stark组件 首先创建一个新的项目,并创建三个app stark就是我 ...

  10. Leetcode 235

    思路1:对于一棵二叉排序树 1.如果当前节点的值小于p,q的值,那么LCA一定在root的右边: 2.如果当前节点的值大于p,q的值,那么LCA一定在root的左边: 3.如果当前节点的值在p,q的值 ...