UVa 12661 Funny Car Racing (dijkstra)
题意:给定一个有向图,每条路有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)的更多相关文章
- UVa - 12661 - Funny Car Racing
先上题目: 12661 Funny Car RacingThere is a funny car racing in a city with n junctions and m directed ro ...
- UVa 12661 - Funny Car Racing(Dijkstra)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA - 12661 Funny Car Racing (Dijkstra算法)
题目: 思路: 把时间当做距离利用Dijkstra算法来做这个题. 前提:该结点e.c<=e.a,k = d[v]%(e.a+e.b); 当车在这个点的1处时,如果在第一个a这段时间内能够通过且 ...
- UVa 12661 Funny Car Racing【 dijkstra 】
题意:给出n个点,m条路,每条路用5个整数表示u,v,a,b,t u表示这条路的起点,v表示终点,a表示打开时间,b表示关闭时间,t表示通过这条道路需要的时间 看的紫书,因为边权不再仅仅是路上的时间, ...
- UVa 12661 Funny Car Racing - spfa
很简单的一道最短路问题.分情况处理赛道的打开和关闭. Code /** * UVa * Problem#12661 * Accepted * Time:50ms */ #include<iost ...
- UVA 12661 Funny Car Racing 有趣的赛车比赛(最短路,变形)
题意:赛道有n个交叉点,和m条单向路径(有重边),每条路都是周期性关闭的,且通过仍需一段时间.在比赛开始时,所有道路刚好打开,选择进入该道路必须满足“在打开的时间段进入,在关闭之前出来”,即不可在路上 ...
- 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)
layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...
- 训练指南 UVA - 11374(最短路Dijkstra + 记录路径 + 模板)
layout: post title: 训练指南 UVA - 11374(最短路Dijkstra + 记录路径 + 模板) author: "luowentaoaa" catalo ...
- UVa 12661 (单源最短路) Funny Car Racing
题意: 有一个赛车跑道,可以看做一个加权有向图.每个跑道(有向边)还有一个特点就是,会周期性地打开a秒,然后关闭b秒.只有在赛车进入一直到出来,该跑道一直处于打开状态,赛车才能通过. 开始时所有跑道处 ...
随机推荐
- POI-----POI操作Excel-4、字体
- css实现弹出窗体始终垂直水平居中
<!DOCTYPE html><html> <head> <meta charset=" utf-8"> <meta name ...
- kubernetes管理之使用yq工具截取属性
系列目录 前面我们讲解过使用go-template或者jsonpath格式(kubectl get 资源 --output go-tempalte(或jsonpath))来截取属性的值,并且我们比较了 ...
- mac osx 下编译 OpenWrt
默认的文件系统hfs大小写不敏感.新建一个磁盘镜像文件并合式化为hfs+, 然后挂载到系统中. hdiutil create -size 20g -fs "Case-sensitive HF ...
- 计算IMEI号的校验位
计算IMEI号的校验位 移动设备国际识别码(IMEI:International Mobile Equipment Identification Number)是差别移动设备的标志,具有唯一性,贴在手 ...
- 在“云基础设施即服务的魔力象限”报告中,AWS 连续三年被评为领导者
在"2014 云基础设施即服务的魔力象限"中.Gartner 将 Amazon Web Services 定位在"领导者象限"中,并评价 AWS 拥有最完整.最 ...
- 在XP上安装VS2002
在2002 年,随着 .NET 口号的提出与 Windows XP/Office XP 的公布,微软公布了 Visual Studio .NET(内部版本为 7.0). 使用VS2002+Object ...
- 九度OJ 1100:最短路径 (最短路径)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4185 解决:619 题目描述: N个城市,标号从0到N-1,M条道路,第K条道路(K从0开始)的长度为2^K,求编号为0的城市到其他城市的 ...
- html5 canvas基本用法
通过对canvas的初步了解,经过几天的总结,吧canvas的基本用法总结如下:方便以后查阅 <!doctype html> <html> <head> <m ...
- CSU - 1529 Equator —— DP 最大连续和子序列
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1529 题解: 一个加强版的最大连续和子序列,序列可以从末尾元素转到首元素. 分两种情 ...