zoukankan      html  css  js  c++  java
  • 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
    ",out);
        }
        return 0;
    }
  • 相关阅读:
    maven 错误:读取 xxx.jar 时出错;invalid LOC header (bad signature) 1 错误
    设计模式总结篇系列:建造者模式(Builder)
    java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to
    Rxlifecycle使用详解,解决RxJava内存泄露问题
    详细解析RxAndroid的使用方式
    Android开源项目:GifView——Android显示GIF动画
    Rxjava2的学习与总结
    Pycharm连接gitlab
    Pycharm+Django+Python+MySQL开发 后台管理数据库
    Django-Model操作数据库(增删改查、连表结构)
  • 原文地址:https://www.cnblogs.com/jhz033/p/7284679.html
Copyright © 2011-2022 走看看