URAL 1205 By the Underground or by Foot?(SPFA)
By the Underground or by Foot?
Memory limit: 64 MB
To do that you may move by foot or use the underground. Moving by the
underground is faster but you may enter and exit it only at the
stations. To save your time you decided to write a program to find the
fastest route.
Input
first line contains two floating point numbers. First of them is the
speed of traveling by foot. The second one is the speed of traveling by
the underground. The second speed is always greater than the first one.
station). Then the description of the connections between stations
follows. Each connection is determined by the pair of integers, i.e. by
the numbers of connected stations. The list of connections is terminates
with a pair of zeroes. We assume that all the connections are straight.
So the time we need to travel between stations is equal to the distance
between stations divided by the speed of traveling by the underground.
should be mentioned also that entering and exiting the underground and
changing trains are possible at the stations only and takes no time.
Output
The second line describes the use of the underground while traveling.
It starts with the number of visited stations with tha following list of
visited stations in the order they should be visited.
Sample
input | output |
---|---|
1 100 |
2.6346295 |
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 0x3f3f3f3f
#define mod 10000
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int n,m,k=;
double a,b;
int vis[N],pre[N];
double w[N][N],d[N];
char str[];
bool flag=false;
struct man{
double x,y;
}point[N];
void spfa()
{
d[]=;
vis[]=;
queue<int>q;
q.push();
while(!q.empty()){
int t=q.front();q.pop();
vis[t]=;
for(int i=;i<=n+;i++){
if(d[i]>d[t]+w[t][i]){
d[i]=d[t]+w[t][i];
pre[i]=t;
if(!vis[i])q.push(i),vis[i]=;
}
}
}
}
int main() {
for(int i=;i<N;i++){
d[i]=;
for(int j=;j<N;j++){
w[i][j]=;
}
}
scanf("%lf%lf",&a,&b);
scanf("%d",&n);
int u,v; for(int i=;i<=n;i++){
scanf("%lf%lf",&point[i].x,&point[i].y);
}
while(~scanf("%d%d",&u,&v)&&u&&v){
double s=sqrt((point[u].x-point[v].x)*(point[u].x-point[v].x)+(point[u].y-point[v].y)*(point[u].y-point[v].y));
w[u][v]=w[v][u]=s/b;
}
scanf("%lf%lf%lf%lf",&point[].x,&point[].y,&point[n+].x,&point[n+].y);
for(int i=;i<=n+;i++){
for(int j=i+;j<=n+;j++){
if(w[i][j]<)continue;
double s=sqrt((point[i].x-point[j].x)*(point[i].x-point[j].x)+(point[i].y-point[j].y)*(point[i].y-point[j].y));
w[i][j]=w[i][j]=s/a;
}
}
spfa();
printf("%.7lf\n",d[n+]);
stack<int>p;
for(int i=n+;pre[i];i=pre[i]){
p.push(pre[i]);
}
printf("%d",p.size());
while(!p.empty())printf(" %d",p.top()),p.pop();
return ;
}
URAL 1205 By the Underground or by Foot?(SPFA)的更多相关文章
- 1205: 求一元二次方程的实数根(C)
一.题目 acm.wust.edu.cn/problem.php?id=1205&soj=0 二.分析 一元二次方程有三个系数a.b.c,两个根x1.x2,以及d(德尔塔): a.b.c均为实 ...
- 1205. By the Underground or by Foot?(spfa)
1205 简单题 有一些小细节 两个站可能不相连 但是可以走过去 #include <iostream> #include<cstdio> #include<cstrin ...
- URAL 1104 Don’t Ask Woman about Her Age(数论)
题目链接 题意 : 给你一个数,未知进制,然后让你从2到36进制中找出一个最小的进制K,满足给你的这个数作为k进制时能够整除k-1. 思路 : 有一个公式,(a*b^n)mod(b-1)=a: 给定你 ...
- URAL 1099 Work scheduling 一般图的最大匹配 带花树算法(模板)
R - Work scheduling Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- URAL 1876 Centipede's Morning(数学)
A centipede has 40 left feet and 40 right feet. It keeps a left slippers and b right slippers under ...
- URAL 1549 Another Japanese Puzzle(构造)
题目大意 构造一条闭合路线,使得路线不能相交,并且走直线的步数小于等于 S,转弯(左转和右转)的步数小于等于 T.(0≤S,T≤1000) 求一条最长的路线 做法分析 注意到,因为要求路线闭合,那么转 ...
- URAL 1139 City Blocks(数论)
The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...
- URAL 1208 Legendary Teams Contest(DFS)
Legendary Teams Contest Time limit: 1.0 secondMemory limit: 64 MB Nothing makes as old as years. A l ...
- URAL 1119. Metro(BFS)
点我看题目 题意 : 这个人在左下角,地铁在右上角,由很多格子组成的地图,每一条边都是一条路,每一条边都是100米.还有的可以走对角线,问你从起点到终点最短是多少. 思路 : 其实我想说一下,,,, ...
随机推荐
- 【python】list。列表
列表 list 特点:有序,支持不同类型的元素在一个列表中,可变(使用sort方法排序,影响到的是列表自身而不是创建新的列表——这与字符串不同,所以说字符串是不可变的) 在python中列表也是对象, ...
- SQL2008:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。
错误: 解决方案: 1.查看服务是否开启,如果没有开启,请开启服务. 2.服务器名称栏:格式:主机名\实例名或者ip\实例名 如:10.10.4.81\SQLSERVER
- PHP中函数的使用
函数是一种可以在任何被需要的时候执行的代码块函数的定义 1.函数是一个被命名的独立的代码段 2.它执行特殊的任务 3.并可以给调用它的程序返回值 函数的优点: 1.提高程序的重 ...
- 11、C#基础整理(特殊集合和哈希表)
特殊集合:队列.栈 一.栈Stack类:先进后出,没有索引 Stack ss = new Stack(); 1.增加数据:push :将元素推入集合 ss.Push(); ss.Push(); ss. ...
- HDU 5405 (树链剖分+线段树)
Problem Sometimes Naive 题目大意 给你一棵n个节点的树,有点权. 要求支持两种操作: 操作1:更改某个节点的权值. 操作2:给定u,v, 求 Σw[i][j] i , j ...
- Team Foundation API - 编程控制文件版本
Team Foundation Server (TFS)工具的亮点之一是文件的版本控制.在TFS中实现文件版本控制的类型: Microsoft.TeamFoundation.Client.TfsTea ...
- magento添加多个产品到购物车(Add multiple products to cart )
Step 1app\design\frontend\base\default\template\catalog\product\list.phtml<?php $_productColl ...
- latex figure \label 放在\caption 后
http://www.cnblogs.com/loca/p/4264686.html latex figure \label 放在\caption 后,否则将显示\section 或者\subsect ...
- dedecms头部标签(标题,关键词,描述标签)(借用)
先说说dedecms头部标题,关键词,描述标签的作用我相信网络上也有很多这样的信息,那为什么我还要写这个?因为这个对我们初学者来说还是比较重要的,因为做SEO就要用到这些标签.首先我写下首页头部标签我 ...
- linux监控nmon和analyser的使用
测试压力的时候使用linux一个简单的监控工具nmon,不仅可以实时监测,也可以生成文件以图标样式展现,小巧实用 安装nmon nmon实际上是个tarball直接解压到所要放置的目录,然后直接运行就 ...