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. 慢吞吞的pip切换源

    http://blog.csdn.net/gz_liuyun/article/details/52778198

  2. Bing词典vs有道词典比对测试报告——体验篇之成长性及用户控制权

    成长性: 会记住曾经查询过的单词或例句与有道词典实现基本一样,并无特别亮点. 用户有控制权: 必应词典和有道词典都能实现基本的查询前进和后退.以及无法查找结果,能顺利进行反馈. 我们在输入完单词按下回 ...

  3. 将eclipse上的web项目部署到Tomcat服务器上经验总结

    1.  将Tomcat插件添加到eclipse上 Window --> Preferences --> Server --> Runtime Environment --> A ...

  4. Daily Scrumming* 2015.10.26(Day 7)

    一.总体情况总结 今天我们开会具体讨论了一下接下来的任务.还详细讨论了一下分数的分配,具体分数分配我们会在下一篇博客中详细说明. 我们下一周大致的工作安排如下: 1.UI:完成社团后台界面的设计,以及 ...

  5. 第二阶段每日站立会议Fifth Day

    昨天继续调试手机界面,解决了Tomcat服务可以打开,但是无法连接到数据库的问题 今天做最后的准备阶段,完善卖家后台管理界面

  6. Leetcode题库——17.电话号码的字母组合

    @author: ZZQ @software: PyCharm @file: letterCombinations.py @time: 2018/10/18 18:33 要求:给定一个仅包含数字 2- ...

  7. Leetcode题库——5.最长回文子串

    @author: ZZQ @software: PyCharm @file: longestPalindrome.py @time: 2018/9/18 20:06 要求:给定一个字符串 s,找到 s ...

  8. MapReduce编程之Semi Join多种应用场景与使用

    Map Join 实现方式一 ● 使用场景:一个大表(整张表内存放不下,但表中的key内存放得下),一个超大表 ● 实现方式:分布式缓存 ● 用法: SemiJoin就是所谓的半连接,其实仔细一看就是 ...

  9. Internet History, Technology and Security (Week 6)

    Week 6 Technology: Transport Control Protocol (TCP) Welcome to Week 6 of IHTS. We are in our second ...

  10. 结对编程:四则运算。组员:闫浩楠 杨钰宁 开发语言:C语言

    需求分析:1.能够自动出题并给出答案 2.包含“+,—,*,/,()” 的四则运算. 3.显示题目的答案 结构设计:1.自动出题用随机数生成语句实现:包括随机生成数字.运算符号和题目长度 2.用变量约 ...