CSU 1333 Funny Car Racing (最短路)
题目链接: 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 (最短路)的更多相关文章
- CSU 1333 Funny Car Racing
最短路问题稍微复杂了一点,松弛的时候多判断一些条件就可以了.第一次用SPFA写最短路. #include<cstdio> #include<cmath> #include< ...
- CSU - 1333 1333: Funny Car Racing(spfa)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 这题多了一个限制条件是每一条路都会规律的开放a时间关闭b时间,车子必须在开放的时候进入,在关 ...
- 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 ...
- Funny Car Racing(最短路变形)
描述 There is a funny car racing in a city with n junctions and m directed roads. The funny part is: e ...
- CSU——2161: 漫漫上学路 最短路
Description 众所周知,CSU(California State)University) 的上课地点距离学生公寓很远,对于爱睡懒觉的小Z来说,每天去上课就成了一件非常头疼的事,如果有早课的话 ...
- 【最短路】【数学】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), ...
- 【最短路】【STL】CSU 1808 地铁 (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1808 题目大意: N个点M条无向边(N,M<=105),每条边属于某一条地铁Ci ...
- CSU 1808 - 地铁 - [最短路变形]
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 Time limit: 5000 ms Memory limit: 13107 ...
- csu - 1659 Graph Center(最短路)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1659 题意是找一个图的中心,图的中心定义是某一个点到其他点的最大距离最小,如果有多个排序输出. 注 ...
随机推荐
- 深入剖析z-index属性
一.z-index七阶层叠顺序表 1.层叠顺序的大小比较: background/border < 负z-index < block块状水平盒子 < float浮动盒子 < i ...
- easyui numberbox一些常用属性,方法
1.value="1234567.89"//数字框中的值 2.precision:2//精度(小数点后两位) 3.groupSeparator:','//(组分隔符) 4.deci ...
- 10月16日下午MySQL数据库CRUD操作(增加、删除、修改、查询)
1.MySQL注释语法--,# 2.2.后缀是.sql的文件是数据库查询文件. 3.保存查询. 关闭查询时会弹出提示是否保存,保存的是这段文字,不是表格(只要是执行成功了表格已经建立了).保存以后下次 ...
- Maven打包可执行jar
参考文献:http://blog.csdn.net/xiao__gui/article/details/47341385 方法:使用assembly插件,生成的jar包名为xxx-jar-with-d ...
- 用javascript替换URL中的参数值
<script> function changeUrlArg(url, arg, val){ var pattern = arg+'=([^&]*)'; var replaceTe ...
- thikphp创建共享数据config.php
要求:前台,后台:只需要配置一个config.php 其他文件共享 默认配置是 Index/Conf/config.php Admin/Conf/config.php 代码: return array ...
- 【Delphi】获取EIP
var EIP: Cardinal; procedure GetEIP(); stdcall; asm pop eax; mov EIP,eax; push eax; end; procedure T ...
- iOS 在UILabel显示不同的字体和颜色(转)
转自:http://my.oschina.net/CarlHuang/blog/138363 在项目开发中,我们经常会遇到在这样一种情形:在一个UILabel 使用不同的颜色或不同的字体来体现字符串, ...
- 409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- mysql配置mysql-proxy读写分离
MySQL配置读写分离 192.168.23.131与192.168.23.132两台服务器,131是主,132是从,131是读写,132是只读.myql-proxy的IP是192.168.23.13 ...