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 ...
随机推荐
- crosstool-ng搭建交叉编译环境注意事项
一,crosstool-ng的下载及编译方法 可以参考如下网站: http://www.crosstool-ng.org/ 二,编译过程注意事项 1)如果遇到有些代码包不能下载,请依据指定版本,在这里 ...
- iOS 源代码混淆(初步混淆)
我们可以用classdump对原程序进行 dump,像上篇文章( Class-dump 安装和使用记录(导出应用的头文件)),我们可以看到所有.h 文件全暴露了(如下图) 点击HWAccount.h后 ...
- 课堂讨论—Alpha版总结会议
我们在课堂上针对第一阶段冲刺过程中存在的问题,展开了激烈的讨论,并投票选出需要改进的最主要三个问题. 有图有真相:
- 作业3//Calculator::1
计算器 作业博客 github 1.扯淡 代码其实是在十几号时打的,花了半晚上加半个下午.但是懒得打随笔,所以到现在才完成. 我的课程里没找到queue,是百度照着瞎打的. 2.总结 不大理解要求,S ...
- 牛客网国庆集训派对Day6 题目 2018年
链接:https://www.nowcoder.com/acm/contest/206/A来源:牛客网 Birthday 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576 ...
- Daily target小队介绍(刘畅,陈杰,杨有存,唐祎琳,王晓哲,邵汝佳)
一.团队介绍 1.团队构成: 2.队名: Daily target,我们的口号是Target your day! 3.团队项目描述: 我们计划写一个用于老师发布任务,学生接受任务的安卓app.教师安排 ...
- angularJS1笔记-(3)-购物车增删改查练习
html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 封装react组件——三级联动
思路: 数据设计:省份为一维数组,一级市为二维数组,二级市/区/县为三维数组.这样设计的好处在于根据数组索引实现数据的关联. UI组件: MUI的DropDownMenu组件或Select Field ...
- Asp.net MVC area
妈的,今天去携程面试,技术面了三轮,竟然让我走了,没有然后了,你不要老子,干嘛还面那么多轮,害的老子一上午的时间没了,气死我了. 好了,总结下面试中的问题吧, 1.GC 2.设计模式 3.做过的项目的 ...
- [cnbeta] 波音系列飞机价格。。。
https://www.cnbeta.com/articles/tech/786745.htm 单价最便宜的是波音737-700,为0.858亿美元(约合5.96亿元). 评论网友调侃,“你家能满40 ...