您的位置:首页 > 其它

hdu 6071 Lazy Running 最短路建模

2017-08-04 13:51 441 查看

Lazy Running

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



[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
The 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.

[align=left]Output[/align]
For each test case, print a single line containing an integer, denoting the minimum distance.

[align=left]Sample Input[/align]

1
2000 600 650 535 380

[align=left]Sample Output[/align]

2165

Hint

The best path is 2-1-4-3-2.

[align=left]Source[/align]
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]
;
int vis[5]
;
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("%lld\n",out);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: