hdu-6071 Lazy Running
In HDU, you have to run along the campus for 24 times, or you will fail in PE. According to the rule, you must keep your speed, and your running distance should not be less than K meters.
There are 4 checkpoints in the campus, indexed as p1,p2,p3 and p4.
Every time you pass a checkpoint, you should swipe your card, then the
distance between this checkpoint and the last checkpoint you passed will
be added to your total distance.
The system regards these 4 checkpoints as a circle. When you are at checkpoint pi, you can just run to pi−1 or pi+1(p1 is also next to p4). You can run more distance between two adjacent checkpoints, but only the distance saved at the system will be counted.
Checkpoint p2
is the nearest to the dormitory, Little Q always starts and ends
running at this checkpoint. Please write a program to help Little Q find
the shortest path whose total distance is not less than K
InputThe first line of the input contains an integer T(1≤T≤15), denoting the number of test cases.
In each test case, there are 5 integers K,d1,2,d2,3,d3,4,d4,1(1≤K≤1018,1≤d≤30000), denoting the required distance and the distance between every two adjacent checkpoints.OutputFor each test case, print a single line containing an integer, denoting the minimum distance.Sample Input
1
2000 600 650 535 380
Sample Output
2165
Hint
The best path is 2-1-4-3-2.
OJ-ID:
hdu-6071
author:
Caution_X
date of submission:
20191024
tags:
dp+dijkstra
description modelling:
有四个点1,2,3,4形成环1-2-3-4-1,四条边的权值表示距离,问能否找到一条路径从点2出发回到点2并且权值之和大于K
major steps to solve it:
w=min(d1,d2),其中d1是1,2之间的距离,d2是2,3之间的距离
假设有符合条件的最小权值和P,那么就会有最佳的P-w
设dp[i][j]:=从2出发到达i点时的最小权值和,其中j是权值和%(2*w),之所以%(2*w)是因为从2出发再回到2权值和最少2*w
同样是从2到达i点,不同的j表示不同的路径,若j相同但是从2到i的权值和不同,则选择权值和小的
(1)dijkstra更新dp[i][j]
(2)判断dp[2][j]是否大于K,若小于K则不足之处用w填充
AC code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const ll INF = 1e18;
const int MAXN = 6e4 + ;
vector<P> G[MAXN];
ll d[][MAXN];
void dijkstra(ll w, int s) {
for(int i = ; i <= ; i++) {
fill(d[i], d[i] + w, INF);
}
priority_queue<P, vector<P>, greater<P> >q;
q.push(P(, s));
d[s][] = ;
while(!q.empty()) {
P p = q.top(); q.pop();
int v = p.second;
if(p.first > d[v][p.first % w]) continue;
for(int i = ; i < (int)G[v].size(); i++) {
P e = G[v][i];
ll dist = e.first + d[v][p.first % w];
if(dist < d[e.second][dist % w]) {
d[e.second][dist % w] = dist;
q.push(P(dist, e.second));
}
}
}
}
int main() {
int T;
cin >> T;
while(T--) {
memset(G, , sizeof G);
ll K, d1, d2, d3, d4;
cin >> K >> d1 >> d2 >> d3 >> d4;
G[].push_back(P(d1, ));
G[].push_back(P(d1, ));
G[].push_back(P(d2, ));
G[].push_back(P(d2, ));
G[].push_back(P(d3, ));
G[].push_back(P(d3, ));
G[].push_back(P(d4, ));
G[].push_back(P(d4, ));
ll w = * min(d1, d2);
dijkstra(w, );
ll ans = INF;
for(ll i = ; i < w; i++) {
if(d[][i] >= K) {
ans = min(ans, d[][i]);
} else {
ll nd = K - d[][i];
ans = min(ans, d[][i] + nd / w * w + (nd % w > ) * w);
}
}
cout << ans << endl;
}
return ;
}
hdu-6071 Lazy Running的更多相关文章
- HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4
/* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...
- hdu 6071 Lazy Running 最短路建模
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) P ...
- HDU 6071 Lazy Running (同余最短路 dij)
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- HDU 6071 Lazy Running (同余最短路)
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- HDU 6071 Lazy Running(很牛逼的最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=6071 题意: 1.2.3.4四个点依次形成一个环,现在有个人从2结点出发,每次可以往它相邻的两个结点跑,求最后回 ...
- HDU 6071 Lazy Running(最短路)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6071 [题目大意] 给出四个点1,2,3,4,1和2,2和3,3和4,4和1 之间有路相连, 现在 ...
- HDU 6071 Lazy Running (最短路)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6071 题解 又是一道虐信心的智商题... 首先有一个辅助问题,这道题转化了一波之后就会化成这个问题: ...
- 2017 Multi-University Training Contest - Team 4 hdu6071 Lazy Running
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6071 题目: Lazy Running Time Limit: 2000/1000 MS (J ...
- HDU 6071 同余最短路 spfa
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- 多校4 lazy running (最短路)
lazy running(最短路) 题意: 一个环上有四个点,从点2出发回到起点,走过的距离不小于K的最短距离是多少 \(K <= 10^{18} 1 <= d <= 30000\) ...
随机推荐
- 写出这个数-PTA
读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 10的100次方. 输出格式: ...
- 最全各种系统版本的XPosed框架资料下载整理
由于XPosed在不同安卓系统版本中对应的版本不同,给很多新手造成极大困扰,本文作者经过几番努力,给大家整理了各个版本对应的xposed框架版本以及相关资料,并附上相关下载链接,希望对大伙有所帮助. ...
- [反汇编]函数开始部分利用mov ebx,esp找到返回地址(_KTRAP_FRAME结构)
我们理解call原理,首先将返回地址压入栈中,之后执行调用. 因此,在一个函数开始部分,esp依旧是上一个栈帧的esp,此时esp指向返回地址. 这就意味着使用 mov ebx,esp,之后 [ebx ...
- Think in Speed (关于速度的一点思考)
天下武功,无坚不摧,唯快不破!所以我们重视速度没毛病! 老话说:不要过早优化.赞同! 我们在写代码过程中,有时可能就是为了追求所谓的性能,然后,就给自己挖坑了. 关于开发速度,我有以下几点思考: 1. ...
- 帝国CMS标签【操作类型】说明详解
看标签的参数时候,一般最后一个参数是操作类型说明,可是后面写的是:"操作类型说明 具体看操作类型说明", 这个操作类型说明在什么地方看啊 操作类型 说明 操作类型 说明 0 各栏目 ...
- JQ中的Ajax的封装
1.认识JQ中ajax的封装 jQ 对于ajax的封装有两层实现:$.ajax 为底层封装实现:基于 $.ajax ,分别实现了$.get 与$.post 的高层封装实现: 2.Ajax的底 ...
- 2-How nginx processes a request
原文:http://nginx.org/en/docs/http/request_processing.html server_name directive 参考:http://nginx.org/e ...
- 尉蓝色的P2P金融众筹平台手机模板
蓝色的p2p金融投资众筹网手机模板html整站下载.实用的众筹app手机模板下载.主要页面有:众筹项目.发布.个人中心.登录.注册.优惠券.回报.项目详情.我要支持.帮助中心等总共37个手机页面. 模 ...
- C# Dictionary增加的方法
1.简单的函数,实现Dictionary如果有就替换,没有就增加的功能. /// <summary> /// Dictionary增加的方法 /// </ ...
- 强大的Charles的使用,强大的flutter1.9
<a href="http://www.cocoachina.com/articles/37551?filter=ios"> 强大的Charles 强大的flutter