Lazy Running

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 657    Accepted Submission(s): 284

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
题意:求从2点回到2点的路径距离和大于等与K的最小值
 #pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define LL long long
#define mod 1000000007
using namespace std;
LL x,d12,d23,d34,d41;
int t;
struct node{
LL st,we,dis;
}exm,ok;
int vis[][];
int dp[][];
LL d[][];
LL bew;
queue<node> q;
void dij()
{
while(!q.empty())
q.pop();
exm.st=;
exm.we=;
exm.dis=;
q.push(exm);
dp[][]=;
vis[exm.st][exm.we]=;
while(!q.empty()){
exm=q.front();
q.pop();
vis[exm.st][exm.we]=;
LL now,ww;
now=(exm.st)%+;
ww=(exm.dis+d[exm.st][now])%(*bew);
if(dp[now][ww]==-||dp[now][ww]>=exm.dis+d[exm.st][now]){
dp[now][ww]=exm.dis+d[exm.st][now];
if(vis[now][ww]==){
vis[now][ww]=;
ok.st=now;
ok.we=ww;
ok.dis=exm.dis+d[exm.st][now];
q.push(ok);
}
}
now=(exm.st-);
if(now==)
now=;
ww=(exm.dis+d[exm.st][now])%(*bew);
if(dp[now][ww]==-||dp[now][ww]>=exm.dis+d[exm.st][now]){
dp[now][ww]=exm.dis+d[exm.st][now];
if(vis[now][ww]==){
vis[now][ww]=;
ok.st=now;
ok.we=ww;
ok.dis=exm.dis+d[exm.st][now];
q.push(ok);
}
}
} }
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++){
memset(vis,,sizeof(vis));
memset(dp,-,sizeof(dp));
scanf("%lld %lld %lld %lld %lld",&x,&d[][],&d[][],&d[][],&d[][]);
d[][]=d[][];
d[][]=d[][];
d[][]=d[][];
d[][]=d[][];
bew=min(d[][],d[][]);
dij();
LL ans=1e18+;
for(LL j=;j<*bew;j++){
if(dp[][j]==-)
continue;
LL zhong=(max(0LL,x-dp[][j]))/(*bew);
if(dp[][j]+zhong**bew<x)
zhong++;
ans=min(ans,dp[][j]+zhong**bew);
}
printf("%lld\n",ans);
}
return ;
}

HDU 6071 同余最短路 spfa的更多相关文章

  1. HDU 6071 Lazy Running (最短路)

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

  2. hdu 2962 Trucking (二分+最短路Spfa)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others ...

  3. hdu 6071 Lazy Running 最短路建模

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

  4. [模板][HDU]P2544[单源最短路][SPFA]

    题目就不放了,主要是写一下SPFA,很少写,今天特别学了一个用STL的队列来做的. 代码: #include<iostream> #include<cstdio> #inclu ...

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

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

  6. 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】

    还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...

  7. BZOJ 2118 墨墨的等式 (同余最短路)

    题目大意:已知B的范围,求a1x1+a2x2+...+anxn==B存在非负正整数解的B的数量,N<=12,ai<=1e5,B<=1e12 同余最短路裸题 思想大概是这样的,我们选定 ...

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

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

  9. 【CodeChef】LECOINS(同余最短路,背包DP)

    题意:给定n个物品,每个物品可以取无限次,每个物品有两种属性:价值v和颜色c 现在有q个询问,每次询问是否能取出价值和为S的方案,如有多解输出不同颜色种数的最大值 题意:看到BZOJ评论区有好心人说C ...

随机推荐

  1. dos2unix命令详解

    基础命令学习目录首页 原文链接:https://blog.csdn.net/leedaning/article/details/53024290 使用git 的时候碰到git将unix换行符转换为wi ...

  2. HTTP-HTTPS区别

    超文本传输协议HTTP协议被用于在Web浏览器和网站服务器之间传递信息,HTTP协议以明文方式发送内容,不提供任何方式的数据加密,如果攻击者截取了Web浏览器和网站服务器之间的传输报文,就可以直接读懂 ...

  3. ME.kkkK

    ME.kkkK 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 50 40 • Estima ...

  4. Chapter 7 面向对象分析

    面向对象的分析模型由功能模型.分析对象模型.动态模型三个独立的模型组成,从软件的需求功能来看分析类可以划分为实体类.边界类和控制类三种类型.识别分析类.控制类和实体类需要充分理解系统内部的行为.一个参 ...

  5. 【转】python 三种遍历list的方法

    [转]python 三种遍历list的方法 #!/usr/bin/env python # -*- coding: utf-8 -*- if __name__ == '__main__': list ...

  6. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配

    题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...

  7. 【贪心算法】POJ-2376 区间问题

    一.题目 Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cle ...

  8. Week2-作业一——《构建之法》三章精读之想

    Week2-作业一——精读<构建之法> 前言 其实我本人是不经常看书的,电子书倒是看了不少,实体书真的不经常看,但是为了这次作业的需求,我还是选择静下心来阅读一下这本<构建之法> ...

  9. Scrum 5.0(继4.0)

    一,组员任务完成情况 首页设计初步完成但是需要优化界面,只能简单的输出信息和在首页进行登录.界面极其简单. 鸡汤版面设计有困难,问题在于用何种形式来管理用户的数据上传,但是经过小组间的讨论确定设计方向 ...

  10. 软工网络15团队作业8——Beta阶段敏捷冲刺(day1)

    第 1 篇 Scrum 冲刺博客 1. 介绍小组新加入的成员,Ta担任的角色 --给出让ta担当此角色的理由 小组新加入的成员:3085叶金蕾 担任的角色:测试/用户体验/开发 理由:根据小组讨论以及 ...