我是靠谱客的博主 无情板栗,这篇文章主要介绍hdu 6071 Lazy Running 最短路建模Lazy Running,现在分享给大家,希望可以做个参考。

Lazy Running

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)



Problem Description
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 pi1 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.
 

 

Input
The first line of the input contains an integer  T(1T15), denoting the number of test cases.

In each test case, there are 5 integers K,d1,2,d2,3,d3,4,d4,1(1K1018,1d30000), denoting the required distance and the distance between every two adjacent checkpoints.
 

 

Output
For 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.
 

 

Source
2017 Multi-University Training Contest - Team 4
官方题解:

友情链接:https://post.icpc-camp.org/d/674-poi-x-sums 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> #include<bitset> #include<time.h> using namespace std; #define LL long long #define pi (4*atan(1.0)) #define eps 1e-4 #define bug(x) cout<<"bug"<<x<<endl; const int N=6e4+10,M=1e6+10,inf=1e9+7,MOD=1e9+7; const LL INF=1e18+10,mod=1e9+7; struct mmp { int s; LL dis; bool operator <(const mmp &b)const { return dis>b.dis; } }; LL ans[5][N]; int vis[5][N]; priority_queue<mmp>q; vector<pair<int,int> >edge[6]; void dij(int s,int m) { ans[s][0]=0; q.push((mmp){s,0LL}); while(!q.empty()) { mmp now = q.top(); q.pop(); if(vis[now.s][now.dis%m])continue; vis[now.s][now.dis%m]=1; for(int i = 0; i < 2 ; i++) { int v=edge[now.s][i].first; int w=edge[now.s][i].second; int z=(now.dis+w)%m; if(ans[v][z]==-1||ans[v][z] >=now.dis + w) { q.push((mmp){v,now.dis+w}); ans[v][z]=now.dis+w; } } } } int main() { int T; scanf("%d",&T); while(T--) { memset(ans,-1,sizeof(ans)); memset(vis,0,sizeof(vis)); LL x; int d1,d2,d3,d4; scanf("%lld%d%d%d%d",&x,&d1,&d2,&d3,&d4); for(int i=1;i<=4;i++) edge[i].clear(); edge[1].push_back(make_pair(2,d1)); edge[1].push_back(make_pair(4,d4)); edge[2].push_back(make_pair(1,d1)); edge[2].push_back(make_pair(3,d2)); edge[3].push_back(make_pair(4,d3)); edge[3].push_back(make_pair(2,d2)); edge[4].push_back(make_pair(3,d3)); edge[4].push_back(make_pair(1,d4)); dij(2,2*d1); LL out=INF; d1*=2; for(int i=0;i<d1;i++) { if(ans[2][i]==-1)continue; if(ans[2][i]>=x)out=min(out,ans[2][i]); else { LL z=x-ans[2][i]; LL zz=ans[2][i]+(z%d1?(z/d1+1)*d1:z); out=min(out,zz); } } printf("%lldn",out); } return 0; }

 

转载于:https://www.cnblogs.com/jhz033/p/7284679.html

最后

以上就是无情板栗最近收集整理的关于hdu 6071 Lazy Running 最短路建模Lazy Running的全部内容,更多相关hdu内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部