导航软件 CH Round #57 - Story of the OI Class
题目: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的更多相关文章
- CH Round #57 - Story of the OI Class 凯撒密码
很有意思的一道题目 考场上想的是HASH成一个整数,把末位asicc码值*1,依次乘*10,得到一个整数,然后利用等差性.唯一性快排Nlogn乱搞的 证明如下: 对于明文abcde 密文 bcdef ...
- 凯撒密码 CH Round #57 - Story of the OI Class
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/凯撒密码 题解:刚开始想map, ...
- 查错 CH Round #57 - Story of the OI Class
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/查错 题解:刚开始看见立马以为是 ...
- 【拓扑排序】【堆】CH Round #57 - Story of the OI Class 查错
拓扑排序,要让字典序最小,所以把栈改成堆. #include<cstdio> #include<queue> #include<algorithm> using n ...
- CH Round #52 还教室[线段树 方差]
还教室 CH Round #52 - Thinking Bear #1 (NOIP模拟赛) [引子]还记得 NOIP 2012 提高组 Day2 中的借教室吗?时光飞逝,光阴荏苒,两年过去了,曾经借教 ...
- CH Round #72树洞[二分答案 DFS&&BFS]
树洞 CH Round #72 - NOIP夏季划水赛 描述 在一片栖息地上有N棵树,每棵树下住着一只兔子,有M条路径连接这些树.更特殊地是,只有一棵树有3条或更多的路径与它相连,其它的树只有1条或2 ...
- CH Round #30 摆花[矩阵乘法]
摆花 CH Round #30 - 清明欢乐赛 背景及描述 艺术馆门前将摆出许多花,一共有n个位置排成一排,每个位置可以摆花也可以不摆花.有些花如果摆在相邻的位置(隔着一个空的位置不算相邻),就不好看 ...
- contesthunter CH Round #64 - MFOI杯水题欢乐赛day1 solve
http://www.contesthunter.org/contest/CH Round %2364 - MFOI杯水题欢乐赛 day1/Solve Solve CH Round #64 - MFO ...
- CH Round #17 舞动的夜晚
舞动的夜晚 CH Round #17 描述 L公司和H公司举办了一次联谊晚会.晚会上,L公司的N位员工和H公司的M位员工打算进行一场交际舞.在这些领导中,一些L公司的员工和H公司的员工之间是互相认识的 ...
随机推荐
- Effective C++ 笔记三 资源管理
条款13:以对象管理资源 许多资源被动态分配于heap内而后被用于单一区块或函数内.它们应该在控制流离开那个区块或函数时被释放.标准程序库提供的auto_ptr正是针对这种形式而设计的特制产品.aut ...
- Maven浅析-2 什么是Maven
1.简单点讲:Maven就是一个项目构建工具.它可以生成一个artifact(component),还可以帮我们管理项目依赖(如附加的组件Filters等). 2.从整体讲:Maven也可以看作一个项 ...
- less编码规范
Less 编码规范 简介 因为自己最近写css用的比较多还是less,整理了一份less规范, 代码组织 代码按如下形式按顺序组织: @import 变量声明 样式声明 // ✓ @import &q ...
- J2EE入门必备
1,J2EE是什么 J2EE(Java 2 platform Enterprise Edition)是软件平台,适于创建服务器端的大型应用软件和服务系统. J2EE适合开发大规模的业务系统,这种级别的 ...
- Windows环境下使用cygwin ndk_r9c编译x264
一.废话 最近学习,第一步就是编译.我们需要编译FFmpag,x264,fdk_aac,下面是x264,网上说的很多都是几百年前的,我亲测完美可用 还是那句话 我能力有限,但是我希望我写的东西能够让 ...
- Oracle 11g服务
成功安装Oracle 11g后,共有7个服务, 这七个服务的含义分别为: 1. Oracle ORCL VSS Writer Service: Oracle卷映射拷贝写入服务,VSS(Volume S ...
- .NET 设计模式之简单工厂模式(二)
1:建立接口 namespace Factory { public interface IPerson { } } 2:建立Worker.Student来继承IPerson接口 namespace F ...
- Qt Linguist的使用
国际化的英文表述为Internationalization,通常简写为I18N,QT Linguist是一个将“tr(“”)”引号中的语言翻译成另外语言的工具 1. 创建.ts文件 在Creator中 ...
- (一)跟我一起玩Linux网络服务:DNS服务——BIND(/etc/named.conf、/var/named)设置实现和解释
2015年3月24更新 添加了要加的配置域名解析器(否则会找不到域名) 一.创建该实验的的模型 配置完gate虚拟机的两张网卡后,就启动gate的转发 [root@localhost ro ...
- django添加静态文件
最近做了一个todolist webapp,需要稍微添加css时候又忘记django的添加方法了,查看了以前的项目才想起来,所以记录一下. 1.settings.py 将以下代码放到最下面 STATI ...