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)的更多相关文章

  1. UVa 12661 Funny Car Racing - spfa

    很简单的一道最短路问题.分情况处理赛道的打开和关闭. Code /** * UVa * Problem#12661 * Accepted * Time:50ms */ #include<iost ...

  2. 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 ...

  3. CSU 1333 Funny Car Racing (最短路)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒 ...

  4. CSU 1333 Funny Car Racing

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

  5. <一道题>abc+cba=1333,求满足条件的abc的值,隐含条件a!=0,c!=0

    这类东西,无非就是穷举法.见下面代码: #include <stdio.h> #include <stdlib.h> /* *abc + cba = 1333 * *a = ? ...

  6. ural 1333 化平面为点计算覆盖率

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1333 #include<cstdio> #include<cstrin ...

  7. hihocoder#1333 : 平衡树·Splay2 (区间操作)

    题面: #1333 : 平衡树·Splay2 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:好麻烦啊~~~~~ 小Hi:小Ho你在干嘛呢? 小Ho:我在干活啊! ...

  8. 1333:【例2-2】Blah数集

    1333:[例2-2]Blah数集 注意是数组,答案数组中不能有重复数字 q数组是存储答案的 代码: #include<iostream> #include<cstdio> # ...

  9. 用js写已知abc+cba = 1333,其中a、b、c均为一位数,编程求出满足条件的a、b、c所有组合。

    <!--<script type="text/javascript"> //已知abc+cba = 1333,其中a.b.c均为一位数,编程求出满足条件的a.b. ...

随机推荐

  1. 解决okHttp使用https抛出stream was reset: PROTOCOL_ERROR的问题

    昨天在做Android接口调用的时候,api接口是https的,用okhttp抛出: okhttp3.internal.http2.StreamResetException: stream was r ...

  2. leetcode790 Domino and Tromino Tiling

    思路: dp.没有像discuss中的那样优化递推式. 实现: class Solution { public: ; int numTilings(int N) { vector<vector& ...

  3. lua使用lfs.dll库进行文件操作

    在项目开发中,为了提高开发效率往往需要开发一些辅助工具.最近在公司用lua帮拓展了一个资源扫描的工具,这个工具的功能就是从原始demo下指定目标资源文件,对该文件进行读取并筛选过滤一遍然后拷贝到最终d ...

  4. Java:核心概念j积累(一)

    1.      抽象 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节.抽象包括两个方面,一是过 ...

  5. 请大家帮我找一找bug —— 一个MySQL解析程序(JAVA实现)

    周末两天我写了一个MySQLParser.写这个东西的目的是:公司的一个项目中需要对数据打版本号(每个表的每条记录要有一个版本号字段,这个字段需要由框架自动打上去,而不是由程序员来做). 所以,我写的 ...

  6. 【C++】异常简述(三):补充之如何看待C++异常

    C++异常的使用,我相信在上文总结的已经比较完整了,本文主要对C++异常这块进行额外的补充. 即使C++将异常纳入标准已经很多年了,但是直到现在都能看到很多坚持不显式使用异常.(包括本人在内,在写的代 ...

  7. Java.io.ObjectOutputStream.writeObject()方法实例

    java.io.ObjectOutputStream.writeObject(Object obj) 方法将指定对象写入ObjectOutputStream.该对象的类,类的签名,以及类及其所有超类型 ...

  8. elasticsearch学习笔记-倒排索引以及中文分词

    我们使用数据库的时候,如果查询条件太复杂,则会涉及到很多问题 1.无法维护,各种嵌套查询,各种复杂的查询,想要优化都无从下手 2.效率低下,一般语句复杂了之后,比如使用or,like %,,%查询之后 ...

  9. Ubuntu 下更新或下载输入法(搜狗)

    ubuntu12.04的fcitx版本不支持,不满足依赖,需要更新fcitx 添加fcitx源添加fcitx源命令 : sudo add-apt-repository ppa:fcitx-team/n ...

  10. iTOP4418开发板7寸屏幕Android系统下横竖屏设置

    Android系统屏幕旋转设置 平台: iTOP4418开发板+7寸屏幕 1. Androd4.4源码可以编译成手机模式和平板模式,讯为iTop4418 开发平台的Android系统默认编译为平板模式 ...