题目: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. SpringMVC注解@RequestMapping

        /**      * GET 查询      *      * @return 视图路径      */     @RequestMapping(value = {"/index&q ...

  2. Big Data 應用:第二季(4~6月)台湾地区Game APP 变动分布趋势图

    图表简介: 该示意图表示了台湾地区第二季内所有Game APP类别的分布情形,经由该图表我们可以快速的了解到在这三个月内,哪类型的APP是很稳定:抑或者哪类型的APP是非常不稳定的. 名词解释: 类别 ...

  3. 前台添加jquery的引用

    注意引用的顺序. 以下两个引用,因为bxCarousel.js引用了jquery.js所以jquery.js必须在bxCarousel.js的前面.一般来说对jquery.js的引用放在前面. < ...

  4. hibernate - 何时关闭数据库

    ref: http://www.coderanch.com/t/637103/ORM/databases/close-database-connection-hibernate 我上这个问题, 原因是 ...

  5. Windows 7 + Visual Studio 2012 + cocos2d-x 2.1.5

    下载cocos2d-x google code : http://code.google.com/p/cocos2d-x/downloads/list cocos2d 官网: http://cocos ...

  6. 0-C相关01:NSlog函数介绍。

      NSlog()函数介绍: 首先:NSlog()函数是cocoa的框架中提供的一个方法: 下图中最上方是它在Xcode中的路径: : 同样都是输出函数.下边我们来看一下,在O-C中NSlog()和在 ...

  7. ACM HDU 2674 N! Again(数论)

    继续数论.. Problem Description WhereIsHeroFrom:            Zty,what are you doing ? Zty:                 ...

  8. OC中常用的字符处理

    NSString *str1 = @"BeiJing"; NSString *str2 = @"beijing"; //全部转为大写 NSLog(@" ...

  9. v880 debug

    zte v880手机,ubuntu中配置真机调试, 1.开启手机调试模式2.增加/etc/udev/rules.d/51-android.rules. 内容如下:SUBSYSTEM=="us ...

  10. javascript 学习笔记之JQuery中的Deferred对象

    Deffered是Jquery中的一个非常重要的对象,从1.5版本之后,Jquery中的ajax操作都基于Deffered进行了重构,这个对象的处理模式就像其他Javascript框中的Promise ...