PAT1072. Gas Station (30)
题目的测试用例数据有问题!
第一个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)的更多相关文章
- pat 甲级 1072. Gas Station (30)
1072. Gas Station (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A gas sta ...
- 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 ...
- 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 ...
- 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 ...
- 1072. Gas Station (30)
先要求出各个加油站 最短的 与任意一房屋之间的 距离D,再在这些加油站中选出最长的D的加油站 ,该加油站 为 最优选项 (坑爹啊!).如果相同D相同 则 选离各个房屋平均距离小的,如果还是 相同,则 ...
- 1072. Gas Station (30) 多源最短路
A gas station has to be built at such a location that the minimum distance between the station and a ...
- 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 ...
- 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 ...
- PAT (Advanced Level) 1072. Gas Station (30)
枚举一下选的位置,每次算一下就可以了. #include<cstdio> #include<cstring> #include<cmath> #include< ...
随机推荐
- perl 常用命令
过滤重复字符 perl -e '$_=<STDIN>; @in = split; if (@in < 100){ @out = grep {! $hash{$_}++ } @in; ...
- python类可以任意添加属性
python类可以任意添加属性 class A(object): def __init__(self): self.name = "zhangsan" self.age = 18 ...
- day6-面向对象
Python 面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.本章节我们将详细介绍Python的面向对象编程. 如果你以前没有接触过 ...
- 003-spring boot项目的项目属性配置
一.application.properties文件. 1.项目的配置文件内容.配置了端口,超时连接时间, 2.控制器. 3.访问. 二.application.yml文件 1.application ...
- XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game
题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondM ...
- How can For each...
Answer: I understand the IEnumerator/IEnumerable methods and properties and also how they are inte ...
- 了解Java应用中的开发攻击
注入式(Inject)攻击是一类非常常见的攻击方式,其基本特征是允许攻击者将不可信的动态内容注入到程序中,并将其执行,这就可能完全改变最初预计的执行过程,产生恶意效果. 下面是几种主要的注入式攻击途径 ...
- zookeeper No route to host
2017-10-12 07:25:59,270 [myid:1] - WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@36 ...
- hadoop 一些命令
关闭访问墙 service iptables stop hadoop dfs -mkdir input hadoop dfs -copyFromLocal conf/* input hadoop j ...
- Linux中find
Linux中find常见用法示例 ·find path -option [ -print ] [ -exec -ok command ] {} \; find命令的参数 ...