我是靠谱客的博主 无情板栗,最近开发中收集的这篇文章主要介绍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 

#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 6071 Lazy Running 最短路建模Lazy Running所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部