题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/导航软件

题解:刚开始看见题目,这不是裸的分层图spfa吗?

于是开始写代码,读边的时候忽然发现居然还有红绿灯,我说不会这么简单的,那这题一定很神。。。

于是滚去做vijos

看了题解一口血喷出来啊。。。

事后想了想,貌似不管红绿灯什么事,走多少是多少?来的早至少不会比来得迟的过得晚。。。

T_T

计算有红绿灯时通过的时间时需要好好yy一下,注释写在代码里

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 50005
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
struct edge{int go,next,w,t1,t2;}e[*maxn];
int n,m,k,s,t,tot,d[maxn][],head[maxn];
queue<pa> q;
bool v[maxn][];
inline void insert(int x,int y,int t1,int t2,int z)
{
e[++tot].go=y;e[tot].w=z;e[tot].next=head[x];head[x]=tot;e[tot].t1=t1;e[tot].t2=t2;
e[++tot].go=x;e[tot].w=z;e[tot].next=head[y];head[y]=tot;e[tot].t1=t1;e[tot].t2=t2;
}
int calc(int ti,int t1,int t2,int t)
{
if(!t2)return ti+t;
if(!t1)return inf;
int res=ti;
while(t)
{
int tmp=res%(t1+t2);
if(!tmp)
{
if(t%t1)res+=t/t1*t2+t;//需要走t/t1个时间段,而在此之间等待的时间就为t/t1*t2
else res+=(t/t1-)*t2+t;//少等待一个t2,因为最后一次已经走过这条路
t=;
}
else if(tmp<t1)
{
if(t<=t1-tmp)res+=t,t=;
else res+=t1-tmp,t-=t1-tmp;//暴力模拟只走这一段
}
else res+=t1+t2-tmp;//等待
}
return res;
}
int spfa()
{
memset(d,,sizeof(d));
d[s][]=;q.push(pa(s,));
while(!q.empty())
{
int x=q.front().first,z=q.front().second;q.pop();v[x][z]=;
for(int i=head[x];i;i=e[i].next)
{
int y=e[i].go;
if(z<k&&d[x][z]+e[i].w<d[y][z+])
{
d[y][z+]=d[x][z]+e[i].w;
if(!v[y][z+]){v[y][z+]=;q.push(pa(y,z+));}
}
int tmp=calc(d[x][z],e[i].t1,e[i].t2,e[i].w);
if(tmp<d[y][z])
{
d[y][z]=tmp;
if(!v[y][z]){v[y][z]=;q.push(pa(y,z));}
}
}
}
int ans=inf;
for0(i,k)ans=min(ans,d[t][i]);
return ans;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();k=read();
for1(i,m)
{
int x=read(),y=read(),t1=read(),t2=read(),z=read();
insert(x,y,t1,t2,z);
}
s=read();t=read();
printf("%d\n",spfa());
return ;
}

导航软件 CH Round #57 - Story of the OI Class的更多相关文章

  1. CH Round #57 - Story of the OI Class 凯撒密码

    很有意思的一道题目 考场上想的是HASH成一个整数,把末位asicc码值*1,依次乘*10,得到一个整数,然后利用等差性.唯一性快排Nlogn乱搞的 证明如下: 对于明文abcde 密文 bcdef ...

  2. 凯撒密码 CH Round #57 - Story of the OI Class

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/凯撒密码 题解:刚开始想map, ...

  3. 查错 CH Round #57 - Story of the OI Class

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/查错 题解:刚开始看见立马以为是 ...

  4. 【拓扑排序】【堆】CH Round #57 - Story of the OI Class 查错

    拓扑排序,要让字典序最小,所以把栈改成堆. #include<cstdio> #include<queue> #include<algorithm> using n ...

  5. CH Round #52 还教室[线段树 方差]

    还教室 CH Round #52 - Thinking Bear #1 (NOIP模拟赛) [引子]还记得 NOIP 2012 提高组 Day2 中的借教室吗?时光飞逝,光阴荏苒,两年过去了,曾经借教 ...

  6. CH Round #72树洞[二分答案 DFS&&BFS]

    树洞 CH Round #72 - NOIP夏季划水赛 描述 在一片栖息地上有N棵树,每棵树下住着一只兔子,有M条路径连接这些树.更特殊地是,只有一棵树有3条或更多的路径与它相连,其它的树只有1条或2 ...

  7. CH Round #30 摆花[矩阵乘法]

    摆花 CH Round #30 - 清明欢乐赛 背景及描述 艺术馆门前将摆出许多花,一共有n个位置排成一排,每个位置可以摆花也可以不摆花.有些花如果摆在相邻的位置(隔着一个空的位置不算相邻),就不好看 ...

  8. contesthunter CH Round #64 - MFOI杯水题欢乐赛day1 solve

    http://www.contesthunter.org/contest/CH Round %2364 - MFOI杯水题欢乐赛 day1/Solve Solve CH Round #64 - MFO ...

  9. CH Round #17 舞动的夜晚

    舞动的夜晚 CH Round #17 描述 L公司和H公司举办了一次联谊晚会.晚会上,L公司的N位员工和H公司的M位员工打算进行一场交际舞.在这些领导中,一些L公司的员工和H公司的员工之间是互相认识的 ...

随机推荐

  1. 蓝灯官网下载,蓝灯最新版下载,Lantern(蓝灯)

    蓝灯官网下载,蓝灯最新版下载,Lantern(蓝灯)下载 >>>>>>>>>>>>>>>>>> ...

  2. ( 转 )Github配置

    以下转自 http://liuzhijun.iteye.com/blog/1457207 有问题请联系我删除. -----———————————————————————— 如果你的代码不知道放哪里好, ...

  3. Library中的title与Name

    在Library中新增Title字段,其中文件夹的title字段与Name相同,并且默认生成:但是文件的Title字段为空.

  4. adb shell dumpsys package 查看versionCode

    adb shell dumpsys package +包名 输出可以查看包名 aapt dump xmltree xxx.apk AndroidManifest.xml 查看AndroidManife ...

  5. T-SQL切割字符串方法小结 2

    有表tb, 如下: id value ----------- ----------- 1 aa,bb 2 aaa,bbb,ccc 欲按id,分拆value列, 分拆后结果如下: id value -- ...

  6. Play - js/css concatenation & minify

    1. Css We’ll use LESS CSS, all less sources are defined in the app/assets, and they will be compiled ...

  7. JS常用的7中跨域方式总结

    javascript跨域有两种情况:  1.基于同一父域的子域之间,如:a.c.com和b.c.com  2.基于不同的父域之间,如:www.a.com和www.b.com  3.端口的不同,如:ww ...

  8. (转)JS页面间传值

    一:JavaScript静态页面值传递之URL篇 能过URL进行传值.把要传递的信息接在URL上. 例子: 参数传出页面Post.htm—> <input type="text& ...

  9. c、c++混编实现查询本地IP地址

    一.思路 1.要想得到本地IP地址,可以通过本机名来查询,所以首先得得到本机名. 2.牵涉到IP地址,首先想到牵涉到网络协议,因此得加载套接字协议,所以先使用WSAStartup函数完成对Winsoc ...

  10. Hadoop学习第一天

    1.hadoop量大,数目多. 存储:分布式,集群的概念,管理(主节点.从节点),HDFS. 分析:分布式.并行.离线计算框架,管理(主节点.从节点),MapReduce. 来源:GFS->HD ...