题目: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. 什么时候用using (SPSite site = new SPSite(SPContext.Current.Web.Url))

      并不是所有时候都适合用using(){},只有当需要提升用户的权限的时候才会用到using,其他时候都可以直接使用SPContext.Current.Web;             using ...

  2. RESTful 架构风格概述

    http://blog.igevin.info/posts/restful-architecture-in-general/(非常好) http://blog.igevin.info/posts/re ...

  3. AIX filesystemcache引发的Oracle事故

    链接地址: http://www.jydba.net/aix-filesystemcache%e5%bc%95%e5%8f%91%e7%9a%84oracle%e4%ba%8b%e6%95%85/ A ...

  4. 枚举N行N列的自然数列

    数据库环境:SQL SERVER 2005 现有一个需求,要枚举1-50个自然数,分10行5列展示.如图,

  5. (六)Struts2 国际化

    所有的学习我们必须先搭建好Struts2的环境(1.导入对应的jar包,2.web.xml,3.struts.xml) 第一节:国际化简介 国际化(Internationlization),通俗地讲, ...

  6. PLSQL常用时间函数

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

  7. linux命令sed学习笔记

    sed其实就是两个主要的知识点,那就是“怎么选择”和“怎么操作”!

  8. Windows phone 之独立存储

    独立存储命名空间的说明:

  9. Java连接mySql—JDBC连接数据库

    利用JDBC开发数据库 经典应该用框架: 第一步,加载JDBC数据库驱动程序(不同的数据库有不同的数据库驱动,所以在连接数据库之前,需加载驱动) 格式: String driver = "c ...

  10. C#连接、访问MySQL数据库

    一.准备工具 visual stuido(本示例使用visual studio 2010) MySql.Data.dll mysql_installer_community_V5.6.21.1_set ...