题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333

解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒,问从s点到t点的最短时间。一个简单的最短路稍微变了一下。

卡了很久就因为没看到边是单向边,无语。可以用队列优化。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
using namespace std;
const int maxn = ;
struct node
{
int v,a,b;
int t;
};
vector<node> List[maxn]; int ans[maxn];
int visit[maxn],exist[maxn],n,m,s,t;
int main()
{
int kase = ;
while(scanf("%d%d%d%d",&n,&m,&s,&t)!=EOF)
{
for(int i = ;i <= n;++i)
List[i].clear();
int u1,v1,a1,b1,t1;
for(int i = ;i <= m;++i)
{
scanf("%d%d%d%d%d",&u1,&v1,&a1,&b1,&t1);
if(a1 < t1) continue; //不可能通过的路,已经过滤掉了
node t0;
t0.v = v1;
t0.a = a1;
t0.b = b1;
t0.t = t1;
List[u1].push_back(t0);
}
for(int i = ;i <= n;++i)
ans[i] = 0x7fffffff;
memset(visit,,sizeof(visit));
ans[s] = ;
while()
{
int p = -,M = ;
for(int i = ;i <= n;++i)
if(visit[i] == && ans[i] < M)
{
M = ans[i];
p = i;
}
visit[p] = ;
if(p == -) break;
for(int i = ;i < List[p].size();++i)
if(visit[List[p][i].v] == )
{
int lt = ans[p] % (List[p][i].a + List[p][i].b);
if(List[p][i].a - lt >= List[p][i].t)
ans[List[p][i].v] = min(ans[List[p][i].v],ans[p] + List[p][i].t);
else ans[List[p][i].v] = min(ans[List[p][i].v],ans[p] + (List[p][i].a + List[p][i].b - lt + List[p][i].t));
}
}
printf("Case %d: %d\n",kase++,ans[t]);
}
return ;
}

CSU 1333 Funny Car Racing (最短路)的更多相关文章

  1. CSU 1333 Funny Car Racing

    最短路问题稍微复杂了一点,松弛的时候多判断一些条件就可以了.第一次用SPFA写最短路. #include<cstdio> #include<cmath> #include< ...

  2. CSU - 1333 1333: Funny Car Racing(spfa)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 这题多了一个限制条件是每一条路都会规律的开放a时间关闭b时间,车子必须在开放的时候进入,在关 ...

  3. Funny Car Racing CSU - 1333 (spfa)

    There is a funny car racing in a city with n junctions and m directed roads. The funny part is: each ...

  4. Funny Car Racing(最短路变形)

    描述 There is a funny car racing in a city with n junctions and m directed roads. The funny part is: e ...

  5. CSU——2161: 漫漫上学路 最短路

    Description 众所周知,CSU(California State)University) 的上课地点距离学生公寓很远,对于爱睡懒觉的小Z来说,每天去上课就成了一件非常头疼的事,如果有早课的话 ...

  6. 【最短路】【数学】CSU 1806 Toll (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1806 题目大意: N个点M条有向边,给一个时间T(2≤n≤10,1≤m≤n(n-1), ...

  7. 【最短路】【STL】CSU 1808 地铁 (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1808 题目大意: N个点M条无向边(N,M<=105),每条边属于某一条地铁Ci ...

  8. CSU 1808 - 地铁 - [最短路变形]

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 Time limit: 5000 ms Memory limit: 13107 ...

  9. csu - 1659 Graph Center(最短路)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1659 题意是找一个图的中心,图的中心定义是某一个点到其他点的最大距离最小,如果有多个排序输出. 注 ...

随机推荐

  1. UVA1395 Slim Span(枚举最小生成树)

    题意: 求最小生成树中,最大的边减去最小的边 最小值. 看了题解发现真简单=_= 将每条边进行从小到大排序,然后从最小到大一次枚举最小生成树,当构成生成树的时候,更新最小值 #include < ...

  2. eclipse配置gradle

    1.Grandle官网下载Gradle 2.解压文件,配置到环境变量 3.测试安装成功,$ gradle -v 4.打开eclipse,Help-->Install new software,输 ...

  3. Ubuntu修改mysql默认编码的方法

    ubuntu使用apt-get安装mysql后,server的默认编码是latin1,下面把server的编码修改成utf8. 编码相关信息: 1 2 3 4 5 6 7 8 9 10 11 12 1 ...

  4. 处理字符串-String类和正则表达式

    ---基本元字符       . [] | () ---限定元字符      +至少匹配一个 *匹配0个或任意多个 ?匹配0个或1个(默认是贪心的)           当?在(*,+,?,{n},{ ...

  5. unix-ln 命令

    指令名称 : ln 使用权限 :所有使用者 使用方式 : ln [options] source dist, 其中 option 的格式为 : [-bdfinsvF] [-S backup-suffi ...

  6. UILabel UISwitch UISegmentedControl UIAlertView

    基础小控件 /***************************************UIlabel*************************************/ UILabel ...

  7. (转)Java中的String为什么是不可变的

    转自:http://www.importnew.com/7440.html String是所有语言中最常用的一个类.我们知道在Java中,String是不可变的.final的.Java在运行时也保存了 ...

  8. Tips for writing a paper

    Tips for writing a paper 1. Tips for Paper Writing 2.• Before you write a paper • When you are writi ...

  9. 为什么可以用while(cin)?

    为什么可以用while(cin)?   /** * @brief The quick-and-easy status check. * * This allows you to write const ...

  10. haproxy安装

    最近一直在整理之前用过的东西,现在到haproxy了,安装如下: tar xf haproxy-1.4.27.tar.gz cd haproxy-1.4.27 make TARGET=linux26 ...