题意:给定一个有向图,每条路有5个整数修饰,u, v, a, b, t,表示起点为u,终点为v,打开时间a,关闭时间为b,通过时间为t,打开关闭是交替进行的,

问你从s到t最短时间是多少。

析:使用dijkstra算法,从每个结点出发,求最短路,并维护时间的最小值,这个可以用优先队列,然后考虑能不能通过这条路,如果t<a,可以在输入时处理。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-5;
const int maxn = 300 + 10;
const int mod = 1e6;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int to, a, b, t;
};
vector<Node> G[maxn];
int d[maxn]; int dijkstra(int s, int ttt){
priority_queue<P, vector<P>, greater<P> > pq;
pq.push(P(0, s));
fill(d, d+n+1, INF);
d[s] = 0; while(!pq.empty()){
P p = pq.top(); pq.pop();
if(p.second == ttt) return p.first;
int v = p.second;
if(d[v] < p.first) continue;
for(int i = 0; i < G[v].size(); ++i){
Node &u = G[v][i];
int t = p.first % (u.a+u.b);
if(t + u.t <= u.a && d[u.to] > d[v] + u.t){
d[u.to] = d[v] + u.t;
pq.push(P(d[u.to], u.to));
}
else if(t + u.t > u.a){
int tt = u.a + u.b - t + u.t;
if(d[u.to] > d[v] + tt){
d[u.to] = d[v] + tt;
pq.push(P(d[u.to], u.to));
}
}
}
}
return 0;
} int main(){
int kase = 0;
int s, t;
while(scanf("%d %d %d %d", &n, &m, &s, &t) == 4){
int u, v, a, b, tt;
for(int i = 1; i <= n; ++i) G[i].clear();
while(m--){
scanf("%d %d %d %d %d", &u, &v, &a, &b, &tt);
if(tt > a) continue;
G[u].push_back((Node){v, a, b, tt});
}
printf("Case %d: %d\n", ++kase, dijkstra(s, t));
}
return 0;
}

UVa 12661 Funny Car Racing (dijkstra)的更多相关文章

  1. UVa - 12661 - Funny Car Racing

    先上题目: 12661 Funny Car RacingThere is a funny car racing in a city with n junctions and m directed ro ...

  2. UVa 12661 - Funny Car Racing(Dijkstra)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVA - 12661 Funny Car Racing (Dijkstra算法)

    题目: 思路: 把时间当做距离利用Dijkstra算法来做这个题. 前提:该结点e.c<=e.a,k = d[v]%(e.a+e.b); 当车在这个点的1处时,如果在第一个a这段时间内能够通过且 ...

  4. UVa 12661 Funny Car Racing【 dijkstra 】

    题意:给出n个点,m条路,每条路用5个整数表示u,v,a,b,t u表示这条路的起点,v表示终点,a表示打开时间,b表示关闭时间,t表示通过这条道路需要的时间 看的紫书,因为边权不再仅仅是路上的时间, ...

  5. UVa 12661 Funny Car Racing - spfa

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

  6. UVA 12661 Funny Car Racing 有趣的赛车比赛(最短路,变形)

    题意:赛道有n个交叉点,和m条单向路径(有重边),每条路都是周期性关闭的,且通过仍需一段时间.在比赛开始时,所有道路刚好打开,选择进入该道路必须满足“在打开的时间段进入,在关闭之前出来”,即不可在路上 ...

  7. 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)

    layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...

  8. 训练指南 UVA - 11374(最短路Dijkstra + 记录路径 + 模板)

    layout: post title: 训练指南 UVA - 11374(最短路Dijkstra + 记录路径 + 模板) author: "luowentaoaa" catalo ...

  9. UVa 12661 (单源最短路) Funny Car Racing

    题意: 有一个赛车跑道,可以看做一个加权有向图.每个跑道(有向边)还有一个特点就是,会周期性地打开a秒,然后关闭b秒.只有在赛车进入一直到出来,该跑道一直处于打开状态,赛车才能通过. 开始时所有跑道处 ...

随机推荐

  1. Java、C++、Python、Ruby、PHP、C#和JavaScript的理解

    Java.C++.Python.Ruby.PHP.C#和JavaScript和日本动漫里的那些大家熟悉的动漫人物结合起来.依据他们的身世.个人经历来生动的表达各编程语言的发展历程.原文内容例如以下:  ...

  2. Django-select_related优化查询

    对于一对一字段(OneToOneField)和外键字段(ForeignKey),可以使用select_related 来对QuerySet进行优化. select_related 返回一个QueryS ...

  3. Android对apk源代码的改动--反编译+源代码改动+又一次打包+签名【附HelloWorld的改动实例】

    最近遇到了须要改动apk源代码的问题,于是上网查了下相关资料.编写了HelloWorld进行改动看看可行性,经过实验证明此方案可行,而且后来也成功用这种方法对目标apk进行了改动,仅仅只是须要改动的部 ...

  4. kubernetes之计算机资源管理

    系列目录 当你编排一个pod的时候,你也可以可选地指定每个容器需要多少CPU和多少内存(RAM).当容器请求特定的资源时,调度器可以更好地根据资源请求来确定把pod调度到哪个节点上.当容器请求限制特定 ...

  5. Scala随记

    使用Scala首先确保本地Java 8版本,然后按照官网所说,比较流行的方式(1) sbt; (2) IDE "The most popular way to get Scala is ei ...

  6. 如果在 Code First 模式下使用,则使用 T4 模板为 Database First 和 Model First

    web.config里的链接字符串最好和app.config里相同,因为ef的链接字符串需要一些特殊的参数

  7. Local Response Normalization 60 million parameters and 500,000 neurons

    CNN是工具,在图像识别中是发现图像中待识别对象的特征的工具,是剔除对识别结果无用信息的工具. ImageNet Classification with Deep Convolutional Neur ...

  8. ABAP DEMO-2018

    sap Program DEMO 介绍 Program Description BALVBT01 Example SAP program for displying multiple ALV repo ...

  9. hdu1078 FatMouse and Cheese —— 记忆化搜索

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 代码1: #include<stdio.h>//hdu 1078 记忆化搜索 #in ...

  10. Xshell和secureCRT

    作为一名测试人员,xshell和secureCRT用它们来查看日志.排查定位问题,用的时间长了总感觉只是摸着点皮毛,连这两个工具的名字以及它的工作原理都不清楚,就查了点资料来多了解下,虽然可能在日常工 ...