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

 
Input
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.

 
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+,M=1e6+,inf=1e9+,MOD=1e9+;
const LL INF=1e18+,mod=1e9+; struct mmp
{
int s;
LL dis;
bool operator <(const mmp &b)const
{
return dis>b.dis;
}
};
LL ans[][N];
int vis[][N];
priority_queue<mmp>q;
vector<pair<int,int> >edge[];
void dij(int s,int m)
{
ans[s][]=;
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]=;
for(int i = ; i < ; 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]==-||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,-,sizeof(ans));
memset(vis,,sizeof(vis));
LL x;
int d1,d2,d3,d4;
scanf("%lld%d%d%d%d",&x,&d1,&d2,&d3,&d4);
for(int i=;i<=;i++)
edge[i].clear();
edge[].push_back(make_pair(,d1));
edge[].push_back(make_pair(,d4));
edge[].push_back(make_pair(,d1));
edge[].push_back(make_pair(,d2));
edge[].push_back(make_pair(,d3));
edge[].push_back(make_pair(,d2));
edge[].push_back(make_pair(,d3));
edge[].push_back(make_pair(,d4));
dij(,*d1);
LL out=INF;
d1*=;
for(int i=;i<d1;i++)
{
if(ans[][i]==-)continue;
if(ans[][i]>=x)out=min(out,ans[][i]);
else
{
LL z=x-ans[][i];
LL zz=ans[][i]+(z%d1?(z/d1+)*d1:z);
out=min(out,zz);
}
}
printf("%lld\n",out);
}
return ;
}

hdu 6071 Lazy Running 最短路建模的更多相关文章

  1. HDU 6071 Lazy Running (最短路)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6071 题解 又是一道虐信心的智商题... 首先有一个辅助问题,这道题转化了一波之后就会化成这个问题: ...

  2. HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4

    /* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...

  3. HDU 6071 Lazy Running (同余最短路 dij)

    Lazy Running Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)To ...

  4. HDU 6071 Lazy Running (同余最短路)

    Lazy Running Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)To ...

  5. HDU 6071 Lazy Running(很牛逼的最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=6071 题意: 1.2.3.4四个点依次形成一个环,现在有个人从2结点出发,每次可以往它相邻的两个结点跑,求最后回 ...

  6. HDU 6071 Lazy Running(最短路)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6071 [题目大意] 给出四个点1,2,3,4,1和2,2和3,3和4,4和1 之间有路相连, 现在 ...

  7. 多校4 lazy running (最短路)

    lazy running(最短路) 题意: 一个环上有四个点,从点2出发回到起点,走过的距离不小于K的最短距离是多少 \(K <= 10^{18} 1 <= d <= 30000\) ...

  8. HDU 6071 同余最短路 spfa

    Lazy Running Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)To ...

  9. 2017 Multi-University Training Contest - Team 4 hdu6071 Lazy Running

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6071 题目: Lazy Running Time Limit: 2000/1000 MS (J ...

随机推荐

  1. Linux:CPU使用率100%排查方法

    Linux作为一个多任务操作系统,将每个CPU的时间划分为很短的时间片,再通过调度器轮流分配给各个任务使用,因此造成多任务同时运行的错觉. CPU使用率 Linux作为一个多任务操作系统,将每个CPU ...

  2. 传统OGG与Microservice Architecture OGG的通信

    针对当前新出的ogg microservice architect(MA),现在只支持oracle 11g/12c的数据复制和投递.如果有其它版本的oracle或其它数据库,比如 mysql, db2 ...

  3. JOBDU 题目1131:合唱队形

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4546 解决:1445 题目描述: N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合唱队形. ...

  4. make是如何工作的

    在默认的方式下,也就是我们只输入make命令.那么,1.make会在当前目录下找名字叫“Makefile”或“makefile”的文件.2.如果找到,它会找文件中的第一个目标文件(target),在上 ...

  5. JavaScript笔记 #05# 用Regex辅助生成文章目录

    PS. 用来生成个人笔记的目录 1.输入:html文本 <h2>Notes</h2> <p>1.小标题1.正文正文正文</p> <div clas ...

  6. docker 初步使用

    CentOS Linux release 7.2.1511 Docker version 17.03.1-ce 安装与启动 yum直接安装的docker版本较低,推荐这样安装: # 官方,可能网络连不 ...

  7. eclispe设置workspace text file encoding

    在windows下开发,经常会遇到eclipse新导入的工程 java代码中的注释或者字符串中文显示乱码,每次都要一个个项目更改麻烦,特地找了下,可通过如下方法一次性设置.

  8. css-过渡

    css过渡:元素从一种样式逐渐改变为另一种的效果.过渡所需的条件:1.所过渡的元素必须有css样式.2.必须有过渡时间.以下是过渡元素的属性:transition:简写属性,用于在一个属性中设置四个过 ...

  9. 05文件合并脚本--By Mark Lutz

    ''' 合并split.py创建的目录下的所有组分文件以重建文件. 依赖文件名的排序:长度必须一致. ''' import os,sys readsize=1024 def join(fromdir, ...

  10. CentOS Yum 源搭建

    创建yum源服务,主要用到了两个软件createrepo和httpd.前者是创建yum源索引的工具,后者是提供文件在线流浪的功能,当然,除了httpd之外,你也可以使用nginx替代. creater ...