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

第一个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. Java技术大牛需要学习的25个技能

    你需要精通面向对象分析与设计(OOA/OOD).涉及模式(GOF,J2EEDP)以及综合模式.你应该了解UML,尤其是class.object.interaction以及statediagrams. ...

  2. shell 从文件中读取批量文件名并做命令行操作

    222文件内容: /home/zhangsuosheng/Desktop/9-30/9_30/1bak/1538291162.png /home/zhangsuosheng/Desktop/9-30/ ...

  3. Count the string---hdu3336(kmp Next数组的运用)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 题意就是求串s的前缀的个数和: 例如:abab 前缀 个数 a     2 ab    2 ab ...

  4. Linux内核中namespace之PID namespace

    前面看了LInux PCI设备初始化,看得有点晕,就转手整理下之前写的笔记,同时休息一下!!~(@^_^@)~ 这片文章是之前写的,其中参考了某些大牛们的博客!! PID框架的设计 一个框架的设计会考 ...

  5. 《OVN Logical Flows and ovn-trace》翻译

    在本篇文章中,我将解释什么是Logical Flow以及如何使用ovn-trace去更好地理解它们.同时,我也会用一些例子来解释,为什么使用Logical Flow这种抽象模型能让新特性的添加变得出乎 ...

  6. HTML容易遗忘内容(一)

    HTML基础语法: <html> <head> <tiltle>Hello</tiltle> </head> <body bgcolo ...

  7. Linux shell 程序设计

    shell 程序设计 主要的学习内容包含基本思路,语法:变量.条件判断和程序控制,命令列表,函数,命令及执行,调试,grep命令和正则表达式,find命令 什么是shell 适用编写执行相对简单任务的 ...

  8. django高级之爬虫基础

    目录: 爬虫原理 requests模块 beautifulsoup模块 爬虫自动登陆示例 一.爬虫原理 Python非常适合用来开发网页爬虫,理由如下:1.抓取网页本身的接口相比与其他静态编程语言,如 ...

  9. Spring第一弹—-全面阐述Spring及轻重量级容器的划分

    Spring是什么? Spring是一个开源的控制反转(Inversion of Control ,IoC)和面向切面(AOP)的容器框架,它的主要目得是简化企业开发. IOC 控制反转 :   1 ...

  10. 搭建virtualenv

    一.前言 1.什么是virtualenv? 在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目 ...