PAT (Advanced Level) 1072. Gas Station (30)
枚举一下选的位置,每次算一下就可以了。
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<vector>
- #include<map>
- #include<stack>
- #include<queue>
- #include<string>
- #include<algorithm>
- using namespace std;
- const int INF=0x7FFFFFFF;
- const int maxn=+;
- int n,m,k,ds;
- struct Edge
- {
- int u,v;
- int dis;
- }e[*maxn];
- vector<int>g[maxn];
- int tot;
- int flag[maxn],dis[maxn];
- double ans1,ans2;
- int ans;
- int MIN;
- int get(char *s)
- {
- int num=;
- if(s[]!='G')
- {
- for(int i=;s[i];i++)
- num=num*+s[i]-'';
- }
- else
- {
- for(int i=;s[i];i++)
- num=num*+s[i]-'';
- num=num+n;
- }
- return num;
- }
- void SPFA(int s)
- {
- queue<int>Q;
- memset(flag,,sizeof flag);
- for(int i=;i<=n+m;i++) dis[i]=INF;
- Q.push(s); flag[s]=; dis[s]=;
- while(!Q.empty())
- {
- int head=Q.front(); Q.pop(); flag[head]=;
- for(int i=;i<g[head].size();i++)
- {
- int id=g[head][i];
- if(dis[head]+e[id].dis<dis[e[id].v])
- {
- dis[e[id].v]=dis[head]+e[id].dis;
- if(flag[e[id].v]==)
- {
- flag[e[id].v]=;
- Q.push(e[id].v);
- }
- }
- }
- }
- }
- int main()
- {
- scanf("%d%d%d%d",&n,&m,&k,&ds);
- tot=;
- for(int i=;i<=k;i++)
- {
- char u[],v[]; int dis;
- scanf("%s%s%d",u,v,&dis);
- e[tot].u=get(u),e[tot].v=get(v);
- e[tot].dis=dis;
- g[get(u)].push_back(tot),tot++;
- e[tot].u=get(v),e[tot].v=get(u);
- e[tot].dis=dis;
- g[get(v)].push_back(tot),tot++;
- }
- ans1=1.0*INF;
- ans2=1.0*INF;
- MIN=;
- for(int i=n+;i<=n+m;i++)
- {
- SPFA(i);
- int sum=,MIN_NOW=INF;
- for(int j=;j<=n;j++)
- {
- if(dis[j]>ds) {sum=-;break;}
- else
- {
- sum=sum+dis[j];
- MIN_NOW=min(MIN_NOW,dis[j]);
- }
- }
- if(sum==-) continue;
- if(MIN_NOW>MIN)
- {
- MIN=MIN_NOW;
- ans2=1.0*sum/n;
- ans1=1.0*MIN;
- ans=i;
- }
- else if(MIN_NOW==MIN&&1.0*sum/n<ans2)
- {
- ans2=1.0*sum/n;
- ans=i;
- }
- }
- if(MIN==) printf("No Solution\n");
- else
- {
- printf("G%d\n",ans-n);
- printf("%.1lf %.1lf\n",ans1,ans2);
- }
- return ;
- }
PAT (Advanced Level) 1072. Gas Station (30)的更多相关文章
- 【PAT甲级】1072 Gas Station (30 分)(Dijkstra)
题意: 输入四个正整数N,M,K,D(N<=1000,M<=10,K<=10000)分别表示房屋个数,加油站个数,路径条数和加油站最远服务距离,接着输入K行每行包括一条路的两条边和距 ...
- 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)
1072. Gas Station (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A gas sta ...
- 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 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 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 ...
随机推荐
- HDU2673:shǎ崽 OrOrOrOrz
Problem Description Acmer in HDU-ACM team are ambitious, especially shǎ崽, he can spend time in Inter ...
- sublime Text 常用操作
原文出处:http://www.php100.com/html/it/focus/2014/1030/7666.html 1. 多光标操作:只要按下Cmd(Windows系统下Ctrl)键,再用鼠标选 ...
- iOS打包app发给测试人员测试
说明:在项目开发过程中经常需要开发人员将项目打包成ipa包后,发给测试人员进行测试.本文贴图对打包的过程简单介绍. 一.Product ->archive (注意,不能是模拟器状态,如果当前调试 ...
- 自定义AccessDeniedHandler
在Spring默认的AccessDeniedHandler中只有对页面请求的处理,而没有对Ajax的处理.而在项目开发是Ajax又是我们要常用的技术,所以我们可以通过自定义AccessDeniedHa ...
- Head First--设计模式(装饰者模式)
从现在开始,我将以写一个小软件的方式来进行模式识别的学习,包含需求分析,功能模块设计,原理图设计,程序实现这个几个部分,可能具体的模式模块不可能都包括在内. 需求分析:星巴兹咖啡店已经遍布全世界的很多 ...
- bind启动时提示953端口被使用
部署DNS的时候遇到个奇葩的问题,总是提示 couldn't add command channel 0.0.0.0#953: address in use 实际上系统上并没有进程使用953端口.查询 ...
- hostent h_addr_list
struct hostent { char FAR * h_name; /* official name of host */ char FAR * FAR * h_aliases; /* alias ...
- nginx 正则表达式
1.nginx配置基础 1.正则表达式匹配 ~ 区分大小写匹配 ~* 不区分大小写匹配 !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 ^ 以什么开头的匹配 $ 以什么结尾的匹配 转义字符.可 ...
- c#抓取网页内容乱码的解决方案
写过爬虫的同学都知道,这是个很常见的问题了,一般处理思路是: 使用HttpWebRequest发送请求,HttpWebResponse来接收,判断HttpWebResponse中”Content-Ty ...
- Win7 “Bluetooth设置”对话框无法打开,及无法查找到设备
方法是在百度上找到的,试用成功. 1.打开开始菜单中的运行选项,然后在对话框中输入services.msc,回车打开服务界面: 2.然后在弹出来的服务窗口中查找到Bluetooth Support S ...