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< ...
随机推荐
- 适配器模式(Adapter Pattern)--不兼容结果的协调
定义:将一个接口转换成客户希望的另一个接口,使接口不兼容的那些类可以一起工作,其别名为包装器(Wrapper); 分类: 对象适配器:适配器与适配者之间是关联关系; 类适配器:适配器和适配者之间是继承 ...
- 剑指Offer——数组中的逆序对
题目描述: 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P%100 ...
- python爬虫防止IP被封的一些措施
在编写爬虫爬取数据的时候,因为很多网站都有反爬虫措施,所以很容易被封IP,就不能继续爬了.在爬取大数据量的数据时更是瑟瑟发抖,时刻担心着下一秒IP可能就被封了. 本文就如何解决这个问题总结出一些应对措 ...
- 文本情感分类:分词 OR 不分词(3)
为什么要用深度学习模型?除了它更高精度等原因之外,还有一个重要原因,那就是它是目前唯一的能够实现“端到端”的模型.所谓“端到端”,就是能够直接将原始数据和标签输入,然后让模型自己完成一切过程——包括特 ...
- 基于Hadoop的数据仓库Hive
Hive是基于Hadoop的数据仓库工具,可对存储在HDFS上的文件中的数据集进行数据整理.特殊查询和分析处理,提供了类似于SQL语言的查询语言–HiveQL,可通过HQL语句实现简单的MR统计,Hi ...
- supervisor配置与应用
1.简介 supervisor 是一款基于Python的进程管理工具,可以很方便的管理服务器上部署的应用程序.supervisor的功能如下: a. 启动.重启.关闭包括但不限于python进程. b ...
- Linux kernel 'mq_notify'内存错误引用漏洞
更新系统内核即可!参看http://www.cnblogs.com/peteremperor/p/9065998.html
- mysql 及练习题
if() 函数的用法 IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false, mysql,'女','男') as sex fr ...
- 『NiFi 学习之路』简介
『NiFi 学习之路』简介 『NiFi 学习之路』入门 -- 下载.安装与简单使用 『NiFi 学习之路』资源 -- 资料汇总 『NiFi 学习之路』把握 -- 架构及主要组件 『NiFi 学习之路』 ...
- Maven的plugins、pluginManagement和dependencies、dependencyManagement
plugins和dependencies下边配的都是真实使用的. pluginManagement和dependencyManagement下边配的都只是做声明的,一般配置在顶级pom中. 参考链接: ...