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

第一个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. python定义函数时默认参数注意事项

    如果在调用一个函数时,没有传递默认参数,则函数内的默认参数是对函数的默认参数属性__defaults__的引用, 如 def func(arg1=[]): arg1.append(2) 调用func时 ...

  2. Navicat连接mysql8出现1251错误

    我的博客:www.yuehan.online   因为加密方式的问题,在使用mysql8.0的时候需要修改加密规则才能连接navicat. 打开cmd,输入以下命令: ALTER USER 'root ...

  3. html5游戏开发--"动静"结合(二)-用地图块拼成大地图 & 初探lufylegend

    一.前言 本次教程将向大家讲解如何用HTML5将小地图块拼成大地图,以及如何用现有的高级html5游戏开发库件lufylegend.js开发游戏. 首先让我们来了解了解如何用html5实现动画,毕竟“ ...

  4. SAP Idoc 事务码

    SALE Display ALE Customizing SM59 RFC Destinations (Display/Maintain) BD64 Maintenance of Distributi ...

  5. 使用tensorflow 构建rnn网络

    使用tensorflow实现了简单的rnn网络用来学习加法运算. tensorflow 版本:1.1 import tensorflow as tf from tensorflow.contrib i ...

  6. CCoolBar 的替代方案 CDockablePane。

    (阅读受众需有一定MFC知识储备.) (技术支持:http://www.cnblogs.com/shuhaoc/archive/2011/06/26/cdockableform.html) 在以往很多 ...

  7. 从iOS的图片圆角想到渲染

    圆角是一种很常见的视图效果,相比于直角,它更加柔和优美,易于接受.设置圆角会带来一定的性能损耗,如何提高性能是一个需要重点讨论的话题. 大家常见的圆角代码x.layer.cornerRadius = ...

  8. php.ini优化,,,php-fpm

    无论是apache还是nginx,php.ini都是合适的.而php-fpm.conf适合nginx+fcgi的配置. 1)打开PHP的安全模式 PHP的安全模式是个非常重要的PHP内嵌的安全机制,能 ...

  9. Windows下IIS+PHP 5.2的安装与配置

    Windows下IIS+PHP 5.2的安装与配置   Windows下PHP的安装虽然简单,但如果不注意方法,仍然会让你头疼.此外,PHP 5.2版本与之前4.x版本也有一些不同,所以有必要记录一下 ...

  10. php集成财付通支付接口

    <?phpif(!defined('DEDEINC')) exit('Request Error!');/** *财付通接口类 */class tenpay{ var $dsql; var $m ...