hdu 6071 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
官方题解:

友情链接: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("%lld\n",out);
    }
    return 0;
}

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值