1205

简单题 有一些小细节 两个站可能不相连 但是可以走过去

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0xfffffff
vector<int>ed[];
double v1,v2,x[],y[],w[][],dis[];
int n,vis[],pa[],o[];
void spfa(int s,int e)
{
int i;
for(i = ; i <= n ; i++)
dis[i] = INF;
dis[s] = ;
queue<int>q;
vis[s] = ;
q.push(s);
while(!q.empty())
{
int u = q.front();
q.pop();
vis[u] = ;
for(i = ; i < (int)ed[u].size() ; i++)
{
int v = ed[u][i];
if(dis[v]>dis[u]+w[u][v])
{
pa[v] = u;
dis[v] = dis[u]+w[u][v];
if(!vis[v])
{
vis[v] = ;
q.push(v);
}
}
}
}
printf("%.7lf\n",dis[e]);
int g = ,x=e;
while(pa[x]!=s)
{
x = pa[x];
g++;
o[g] = x;
}
printf("%d",g);
for(i = g ; i>= ; i--)
printf(" %d",o[i]);
puts("");
}
double dist(int u,int v)
{
double s = sqrt((x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v]));
return s;
}
int main()
{
int i,j,u,v;
cin>>v1>>v2;
cin>>n;
for(i = ; i <= n ;i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
for(i = ;i <= n+ ; i++)
for(j = ; j <= n+ ; j++)
w[i][j] = INF;
while(scanf("%d%d",&u,&v)!=EOF)
{
if(!u&&!v)
break;
w[u][v] = dist(u,v)/v2;
w[v][u] = w[u][v];
ed[u].push_back(v);
ed[v].push_back(u);
}
for(i = ; i <= n ; i++)
for(j = i+ ;j <= n ;j++)
{
if(w[i][j]==INF)
{
w[i][j] = dist(i,j)/v1;
w[j][i] = w[i][j]/v1;
ed[i].push_back(j);
ed[j].push_back(i);
}
}
scanf("%lf%lf%lf%lf",&x[],&y[],&x[n+],&y[n+]);
for(i = ; i <= n+ ;i++)
{
w[][i] = dist(i,)/v1;
w[i][] = w[][i];
ed[].push_back(i);
ed[i].push_back();
w[n+][i] = dist(i,n+)/v1;
w[i][n+] = w[n+][i];
ed[i].push_back(n+);
ed[n+].push_back(i);
}
n++;
for(i = ; i <= n ;i++)
w[i][i] = ;
spfa(,n);
return ;
}

1205. By the Underground or by Foot?(spfa)的更多相关文章

  1. URAL 1205 By the Underground or by Foot?(SPFA)

    By the Underground or by Foot? Time limit: 1.0 secondMemory limit: 64 MB Imagine yourself in a big c ...

  2. 1210. Kind Spirits(spfa)

    1210 简单模版题 敲个spfa还得瞟下模版.. #include <iostream> #include<cstdio> #include<cstring> # ...

  3. 九度OJ 1205 N阶楼梯上楼问题 (DP)

    题目1205:N阶楼梯上楼问题 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2817 解决:1073 题目描写叙述: N阶楼梯上楼问题:一次能够走两阶或一阶.问有多少种上楼方式. (要 ...

  4. 1450. Russian Pipelines(spfa)

    1450 水题 最长路 #include <iostream> #include<cstdio> #include<cstring> #include<alg ...

  5. 1934. Black Spot(spfa)

    1934 水题 RE了N久 后来发现是无向图 #include <iostream> #include<cstring> #include<algorithm> # ...

  6. 1930. Ivan's Car(spfa)

    1930 简单二维 标记一下是上坡还是下坡 #include <iostream> #include<cstdio> #include<cstring> #incl ...

  7. SiteMesh入门(1-1)SiteMesh是什么?

    1.问题的提出 在开发Web 应用时,Web页面可能由不同的人参与开发,因此开发出来的界面通常千奇百怪.五花八门,风格难以保持一致. 为了统一界面的风格,Struts 框架提供了一个标签库Tiles ...

  8. RecyclerViewLoadMoreDemo【封装上拉加载功能的RecyclerView,搭配SwipeRefreshLayout实现下拉刷新】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 封装含有上拉加载功能的RecyclerView,然后搭配SwipeRefreshLayout实现下拉刷新.上拉加载功能. 在项目中将 ...

  9. [zz]LyX 入门教程

    http://blog.sina.com.cn/s/blog_630e5dec0100w3jl.html The LyX Tutorial by the LyX Team 1 目录 Chapter 1 ...

随机推荐

  1. JAVA类与对象(三)----类定义关键字详解

    static 表示静态,它可以修饰属性,方法和代码块. 1.static修饰属性(类变量),那么这个属性就可以用类名.属性名来访问,也就是使这个属性成为本类的类变量,为本类对象所共有.这个属性就是全类 ...

  2. Wijmo Angular 2 小应用

    Wijmo & Angular 2 小应用 中秋之际,Angular 团队发布 Angular 2 正式版,一款不错的图表控件Wijmo当天宣布支持 . Angular 2移除和替代了 Ang ...

  3. mysql存储过程出现OUT or INOUT argument 10 for routine

    OUT or INOUT argument 10 for routine * is not a variable or NEW pseudo-variable 我查网上很多出现在call的时候没有添加 ...

  4. 高德开发 android 出现 key 鉴权失败

    环境windows + android studio 原因: 曾经更改过key.store 解决办法: 首先运行cmd移动到keystore的目录下keytool -list -keystore 文件 ...

  5. asynDBcenter(复习)

    asynDBCenter asynDBCenter是GS和DBCenter之间的模块,有了他GS访问数据库就是异步的了,以前是同步的,加入某个操作很耗时那么GS就在那等待这个返回值. .对于std:: ...

  6. Linked List vs Array

    Both Arrays and Linked List can be used to store linear data of similar types, but they both have so ...

  7. auto_ptr的设计动机

    auto_ptr的设计动机 C++标准程序库提供的auto_ptr是一种智能型指针(smart pointer),帮助程序员防止“被异常抛出时发生资源泄露”. 函数的操作经常依以下模式进行: 1.获取 ...

  8. POJ 1258 Agri-Net(最小生成树,模板题)

    用的是prim算法. 我用vector数组,每次求最小的dis时,不需要遍历所有的点,只需要遍历之前加入到vector数组中的点(即dis[v]!=INF的点).但其实时间也差不多,和遍历所有的点的方 ...

  9. Javascript实现两张图片的延迟加载

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  10. REST_FRAMEWORK加深记忆-加了API_ROOT及超链接的CASE

    urls.py from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patter ...