CSU - 1333 1333: Funny Car Racing(spfa)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333
这题多了一个限制条件是每一条路都会规律的开放a时间关闭b时间,车子必须在开放的时候进入,在关闭之前出来,那么在加边的时候只要权值>开放时间的就不用加进去了.
还有一个问题是重边,那么用邻接表存储就好,并且这题不用spfa就超时,至于判断到达某一个点的时间,只要比较dist[x]%(temp.a+temp.b)的数即可.
算出来之后a需要判断是否还能够在剩余时间通过这个路口,不然就需要等待。还有算出需要等待的时间后必须判断是不是能更新目标点,否则会wa.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#include <deque>
//#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define INF 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 310
#define maxv 50010
#define mod 1000000000
using namespace std; struct edge
{
int to,weight,a,b;
};
vector<edge>adjmap[maxv]; //动态邻接表
bool in_queue[maxn]; //顶点是否在队列中
int dist[maxn];//源点到各点的最短路径
int nodesum; //顶点数
int edgesum; //边数
int S,T;//起点和终点 void SPFA(int source)
{
deque<int>dq;
int i,j,x,to;
for(int i=;i<=nodesum;i++)
{
in_queue[i]=false;
dist[i]=INF;
}
dq.push_back(source);
dist[source]=;
in_queue[source]=true;
//初始化 完成
while(!dq.empty())
{
x=dq.front(); //取出队首元素
dq.pop_front();
in_queue[x]=false; //访问标记置0 ,同一个顶点可以访问多次,只要dist值变小
for(i=;i<adjmap[x].size();i++)
{
to=adjmap[x][i].to;
edge temp=adjmap[x][i];
// cout<<temp.a<<" "<<temp.b<<endl;
if((dist[x]<INF)&&(dist[to]>dist[x]+temp.weight))
{
int t=dist[x]%(temp.a+temp.b),t1;
//cout<<dist[x]<<" "<<t<<endl;
if(t<=temp.a)
{
if(temp.a-t-temp.weight>=) t1=temp.weight;
else t1=temp.a-t+temp.b+temp.weight;
}
else t1=temp.a+temp.b-t+temp.weight;
// cout<<t1<<endl;
if(dist[to]>dist[x]+t1) dist[to]=dist[x]+t1;
else continue; //注意这里
if(!in_queue[to])
{
in_queue[to]=true;
if(!dq.empty())
{
if(dist[to]>dist[dq.front()]) dq.push_back(to); //大的加入 队尾
else dq.push_front(to); //小的加入队首
}
else dq.push_back(to); //队列为空加入队尾
}
}
}
}
} int main()
{
//Read;
int i,s,e,w,x,y,j=;
edge temp;
while(cin>>nodesum>>edgesum>>S>>T)
{
for(int i=;i<=nodesum;i++) adjmap[i].clear();
for(int i=;i<=edgesum;i++)
{
cin>>s>>e>>x>>y>>w;
if(w<=x)
{
temp.to=e;
temp.weight=w;
temp.a=x,temp.b=y;
adjmap[s].push_back(temp);
}
}
SPFA(S);
cout<<"Case "<<j++<<":"<<" "<<dist[T]<<endl;
}
return ;
}
CSU - 1333 1333: Funny Car Racing(spfa)的更多相关文章
- UVa 12661 Funny Car Racing - spfa
很简单的一道最短路问题.分情况处理赛道的打开和关闭. Code /** * UVa * Problem#12661 * Accepted * Time:50ms */ #include<iost ...
- 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 ...
- CSU 1333 Funny Car Racing (最短路)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒 ...
- CSU 1333 Funny Car Racing
最短路问题稍微复杂了一点,松弛的时候多判断一些条件就可以了.第一次用SPFA写最短路. #include<cstdio> #include<cmath> #include< ...
- <一道题>abc+cba=1333,求满足条件的abc的值,隐含条件a!=0,c!=0
这类东西,无非就是穷举法.见下面代码: #include <stdio.h> #include <stdlib.h> /* *abc + cba = 1333 * *a = ? ...
- ural 1333 化平面为点计算覆盖率
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1333 #include<cstdio> #include<cstrin ...
- hihocoder#1333 : 平衡树·Splay2 (区间操作)
题面: #1333 : 平衡树·Splay2 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:好麻烦啊~~~~~ 小Hi:小Ho你在干嘛呢? 小Ho:我在干活啊! ...
- 1333:【例2-2】Blah数集
1333:[例2-2]Blah数集 注意是数组,答案数组中不能有重复数字 q数组是存储答案的 代码: #include<iostream> #include<cstdio> # ...
- 用js写已知abc+cba = 1333,其中a、b、c均为一位数,编程求出满足条件的a、b、c所有组合。
<!--<script type="text/javascript"> //已知abc+cba = 1333,其中a.b.c均为一位数,编程求出满足条件的a.b. ...
随机推荐
- WAMP配置虚拟目录
1.启动wamp所有服务,输入localhost或localhost:端口号确保wamp环境正常无误. 2.设置httpd.conf 2.1打开文件:单击wamp在电脑右下角的图标=>wamp= ...
- hihocoder offer收割编程练习赛12 D 寻找最大值
思路: 可能数据太水了,随便乱搞就过了. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...
- fullpagejs实现的拥有header和foooter的全屏滚动demo/fullpage footer
fullpagejs实现的拥有header和foooter的全屏滚动, 技术要点:给section元素加fp-auto-height类, <!DOCTYPE html> <html ...
- 微信小程序组件解读和分析:十三、radio单选项目
radio单选项目组件说明: radio:单选项目. radio-group: 单项选择器,内部由多个<radio/>组成. radio单选项目示例代码运行效果如下: 下面是WXML代码: ...
- window下phpstudy开启redis扩展
注:一定要注意自己PHP的版本结构是64还是32位的!其次查看PHP Extension Build是NTS or TS! 1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本(特 ...
- MySQL——sql注入
https://blog.csdn.net/lin_tuer/article/details/54809330 https://github.com/mysqljs/mysql#escaping-qu ...
- WebService 生成客户端
webservice 生成客户端 wsdl2java -encoding UTF-8 -p com.trm -d D:\happywork -client http://localhost/trm-t ...
- template or render function not defined.
template or render function not defined. H_婷 关注 2018.08.16 17:22 字数 106 阅读 3859评论 0喜欢 2 下午写 Vue $par ...
- 类的封装,property特性,类与对象的绑定方法和非绑定方法,
类的封装 就是把数据或者方法封装起来 为什么要封装 封装数据的主要原因是:保护隐私 封装方法的主要原因是:隔离复杂度(快门就是傻瓜相机为傻瓜们提供的方法,该方法将内部复杂的照相功能都隐藏起来了,比如你 ...
- [转]解决右键用notepad++打开提示【ShellExecute failed (2): Is this command Correct? (Fix) 】
最近发现右键使用notepad++打开文件时提示如下错误: ShellExecute failed (2): Is this command Correct? ... 经用搜索引擎搜索得知,应该是开启 ...