HDU 6071 同余最短路 spfa
Lazy Running
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 657 Accepted Submission(s): 284
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.
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.
2000 600 650 535 380
The best path is 2-1-4-3-2.
#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的更多相关文章
- HDU 6071 Lazy Running (最短路)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6071 题解 又是一道虐信心的智商题... 首先有一个辅助问题,这道题转化了一波之后就会化成这个问题: ...
- hdu 2962 Trucking (二分+最短路Spfa)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others ...
- hdu 6071 Lazy Running 最短路建模
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) P ...
- [模板][HDU]P2544[单源最短路][SPFA]
题目就不放了,主要是写一下SPFA,很少写,今天特别学了一个用STL的队列来做的. 代码: #include<iostream> #include<cstdio> #inclu ...
- HDU 6071 Lazy Running (同余最短路 dij)
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...
- BZOJ 2118 墨墨的等式 (同余最短路)
题目大意:已知B的范围,求a1x1+a2x2+...+anxn==B存在非负正整数解的B的数量,N<=12,ai<=1e5,B<=1e12 同余最短路裸题 思想大概是这样的,我们选定 ...
- HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4
/* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...
- 【CodeChef】LECOINS(同余最短路,背包DP)
题意:给定n个物品,每个物品可以取无限次,每个物品有两种属性:价值v和颜色c 现在有q个询问,每次询问是否能取出价值和为S的方案,如有多解输出不同颜色种数的最大值 题意:看到BZOJ评论区有好心人说C ...
随机推荐
- Python基础系列讲解——TCP协议的socket编程
前言 我们知道TCP协议(Transmission Control Protocol, 传输控制协议)是一种面向连接的传输层通信协议,它能提供高可靠性通信,像HTTP/HTTPS等网络服务都采用TCP ...
- 基于spec评论作品
组名:杨老师粉丝群 组长:乔静玉 组员:吴奕瑶 刘佳瑞 公冶令鑫 杨磊 杨金铭 张宇 卢帝同 一.测试目标:拉格朗日2018——飞词 下面是他们的小游戏在运行时的一些截图画面: 1.开始: ...
- [BUAA OO]第三次博客作业
OO第三次博客作业 1. 规格化设计的发展 我认为,规格化设计主要源自于软件设计的两次危机.第一次是由于大量存在的goto语句,让当时被广泛应用的面向过程式的编程语言臃肿不堪,在逻辑性上与工程规模上鱼 ...
- 始入OO课程的殿堂,初识面向对象的奥妙——OO第一次博客总结
当我满怀期待叩开OO的大门,却发现宝藏藏在层层阻难之后 第一次作业 1.度量分析 >关于第一次作业的metrics图分析没有出现标红的McCabe Cyclomatic Complexity或者 ...
- C#窗体随机四则运算 (第四次作业)
---恢复内容开始--- 增量内容:1)处理用户的错误输入,比如输入字母或符号等,处理除法运算中分母为0的情况,处理结果为负数的情况,保证是小学水平不出现负数,比如不能出现5-8=-3这种情况:2)用 ...
- 灵悟礼品网上专卖店——第三阶段Sprint
一.小组成员: 洪雪意(产品负责人) 陈淑筠(Master) 二.组内人员任务情况 已完成的任务: 陈淑筠:主页面的设计 洪雪意:导航条的改进和页面中插入页面的功能 正在进行的任务: 陈淑筠:主页面的 ...
- 修改shell命令的history记录个数
修改history记录的命令如下所示:# vi /etc/profile 找到histsize=1000,将其改为histsize=100(这条可根据实际情况而定). 不重启系统就可让其生效,如下所示 ...
- 【最简单】不用ps也可以批量转换图片格式
不废话直接开始~ 1.新建文件夹,把需要转换的图片放进去,如图: 2.文件夹里建一txt文本,重点来了!txt文本的内容,如果是jpg转为png,则输入“ren *.jpg *.png”,同理png转 ...
- Delphi 获取Ip地址的方法总结
通过注册表获取或修改Ip 想到Windows会把系统网卡相关信息存入注册表,肯定可通过注册表读取具体ip信息.大致思路是找HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\W ...
- es6 javascript对象方法Object.assign()
es6 javascript对象方法Object.assign() 2016年12月01日 16:42:34 阅读数:38583 1 基本用法 Object.assign方法用于对象的合并,将源对象 ...