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. Python学习路线人工智能线性代数知识点汇总

    人工智能和数据分析相关的线性代数知识.比如什么是矢量,什么是矩阵,矩阵的加减乘除.矩阵对角化,三角化,秩,QR法,最小二法.等等 矢量: 高中数学中都学过复数,负数表达式是: a+bi 复数实际上和二 ...

  2. node 读取多个文件、合并多个文件、读写多个文件

    一.读取文件 1.找文件中匹配的内容 let fs = require('fs') let content = fs.readFileSync('/Users/**/desktop/Test.txt' ...

  3. Django框架----logging配置

    我写Django项目常用的logging配置.(追加在setting.py文件中) LOGGING = { 'version': 1, 'disable_existing_loggers': Fals ...

  4. B/S开发介绍

    b/s 的优势: 1.开发成本低 2.管理维护简单 3.产品升级便利 4.对用户的培训费用低 5.用户使用方便,出现故障的概率小 b/s 的不足: 1.安全性不足 2.客户端不能随心变化,受浏览器限制

  5. ubuntu 构建Xilinx交叉编译环境

    嵌入式系统软硬件协同设计实战指南_基于XILINX ZYNQ_13603826.pdf 202页

  6. Eloquent JavaScript #06# class

    索引 Notes this Prototype 类 class符号 覆盖派生属性 Maps Symbols iterator接口 Getters, setters, and statics 继承 in ...

  7. foreve结束

    import asyncio from threading import Thread import time print('main start:',time.time()) async def s ...

  8. Google翻译实现

    https://blog.csdn.net/yingshukun/article/details/53470424 Google翻译实现

  9. django 分页函数

    实现类似: 上一页 1 ... 4 5 7 8 ... 89 下一页 的效果 def pageGenerate(fullList,pagenum,urltype,type,currpage): pag ...

  10. php 获取文件后缀

    /** * 获取文件后缀 * $path 本地存储临时文件路径 * */ private function getFileType($path){ $fp=fopen($path,'r'); $bin ...