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. Sping Boot返回Json格式自定义

    转载请注明http://www.cnblogs.com/majianming/p/8491020.html 在写项目过程中,遇到了需要定义返回的json字段格式的问题 例如在实体属性中,我有一个字段是 ...

  2. React.js 简介

    React.js 是一个帮助你构建页面 UI 的库.如果你熟悉 MVC 概念的话,那么 React 的组件就相当于 MVC 里面的 View.如果你不熟悉也没关系,你可以简单地理解为,React.js ...

  3. MySQL DECIMAL数据类型

    https://blog.csdn.net/zyz511919766/article/details/49335565

  4. 了解java内存回收机制-博客导读

    此文作为读优质博客前的导读文 1.如何判断对象是否该回收 该对象是否被引用,是否处于不可达状态 2.对象的引用机制 强引用.软引用.弱引用.虚引用 3.垃圾回收机制如何回收.算法. 串行回收.并行回收 ...

  5. PostgreSQL执行机制的初步学习

    作为开源数据库的新手,近日有兴对比了Pg和MySQL的查询计划. 通过Pg源码目录下的src\backend\executor\README文件,加上一些简单调试,就能对Pg的执行机制产生一个初步印象 ...

  6. 【译】x86程序员手册34-9.7错误代码

    9.7 Error Code 错误代码 With exceptions that relate to a specific segment, the processor pushes an error ...

  7. redis-3.0.1 sentinel 主从高可用 详细配置

    最近项目上线部署,要求redis作高可用,由于redis cluster还不是特别成熟,就选择了redis sentinel做高可用.redis本身有replication,实现主从备份.结合sent ...

  8. C# 设置系统环境变量

    using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; ...

  9. redis 其他特性

    1.消息订阅与发布 subscribe my1 订阅频道 psubscribe my1* 批量订阅频道,订阅以my1开头的所有频道 publish my1 hello 在指定频道中发布消息,返回值为接 ...

  10. Debug:This kind of launch is configured to openthe debug perspective when it解决办法

    http://blog.sina.com.cn/s/blog_7ca3aa020100zlha.html 启动tomcat时,myeclipse报错: This kind of launch is c ...