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 ...
随机推荐
- lscpi命令详解
基础命令学习目录 lspci是一个用来查看系统中所有PCI总线以及连接到该总线上的设备的工具. 命令格式为 lspci -参数 (不加参数显示所有硬件设备) 至于有哪些参数及其详细用法可以看下这篇博客 ...
- partprobe命令详解
基础命令学习目录首页 原文链接:https://www.jb51.net/LINUXjishu/389836.html linux上,在安装系统之后,可否创建分区并且在不重新启动机器的情况下系统能够识 ...
- 王者荣耀交流协会final发布第四次scrum例会
1.例会照片 成员高远博,冉华,王磊,王玉玲,任思佳,袁玥,王磊,王超同学因参加比赛不在学校,不能出席. master:王玉玲 2.时间跨度 2017年12月4日 18:00 — 18:18,总计18 ...
- bootstrap table的展开行问题
照着网上与api里说的添加detailView属性设置为true,detailFormatter属性为展开后的内容,但是设置之后发现,在表格每一行最前面是多出一列正常该显示"+"的 ...
- Linux基础入门--04
目录结构及文件基本操作 实验介绍: 1.Linux 的文件组织目录结构. 2.相对路径和绝对路径. 3.对文件的移动.复制.重命名.编辑等操作. 一.Linux 目录结构 在讲 Linux 目录结构之 ...
- C++:类中两个易被忽略的默认函数
C++的自定义类中有六个默认的函数,即如果用户没有显式定义这些函数时,C++编译器会类中生成这些函数的默认形式.除了大家所熟知的构造函数.拷贝构造函数.赋值函数和析构函数外,C++为自定义类 还提供了 ...
- Beta Scrum Day 2 — 听说
听说
- js作用域相关笔记
1.js引擎.编译器.作用域. 引擎:负责JS全过程的编译和执行: 编译器:负责语法分析和代码生成: 作用域:负责收集并维护声明组成的查询,以及当前执行代码对这些变量的访问权限(简言之,作用域就是用于 ...
- beta——5
一.提供当天站立式会议照片一张: 二. 每个人的工作 (有work item 的ID) (1) 昨天已完成的工作: 对用户功能的添加. (2) 今天计划完成的工作: web发布 (3) 工作中遇到的困 ...
- vue开发完成后打包后图片路径不对
用vue做了一个小的移动端项目,从头到尾做下来,感觉自己好多东西都没弄清楚过.也学到了很多,已整理笔记在自己电脑上,但是比较零散,空了再来仔细整理整理. 于是,上周五模拟好数据(接口还未写),准备打包 ...