HDU 6071 Lazy Running (同余最短路 dij)
Lazy Running
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1384 Accepted Submission(s): 597
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.
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 6e4+;;
const int M = ;
const int mod = ;
const int mo=;
const double pi= acos(-1.0);
typedef pair<int,int>pii;
typedef pair<ll,int>P;
int n,s;
ll dis[][N];
ll k,edg[][],m,ans;
void dij(int s){
priority_queue<P,vector<P>,greater<P> >q;
for(int i=;i<;i++){
for(int j=;j<=m;j++){
dis[i][j]=1e18;
}
}
q.push(P(0LL,s));
while(!q.empty()){
ll w=q.top().first;
int u=q.top().second;
q.pop();
if(u==s){
if(w<k){
ans=min(ans,w+((k-w-)/m+)*m);
}
else ans=min(ans,w);
}
for(int i=;i<;i++){
if(!edg[u][i])continue;
ll d=w+edg[u][i];
if(dis[i][d%m]>d){
dis[i][d%m]=d;
q.push(P(d,i));
}
}
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
ans=1e18;
scanf("%lld",&k);
for(int i=;i<;i++){
scanf("%lld",&edg[i][(i+)%]);
edg[(i+)%][i]=edg[i][(i+)%];
}
m=*min(edg[][],edg[][]);
ans=((k-)/m+)*m;
dij();
printf("%lld\n",ans);
}
return ;
}
HDU 6071 Lazy Running (同余最短路 dij)的更多相关文章
- HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4
/* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...
- HDU 6071 Lazy Running (同余最短路)
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- hdu 6071 Lazy Running 最短路建模
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) P ...
- HDU 6071 Lazy Running (最短路)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6071 题解 又是一道虐信心的智商题... 首先有一个辅助问题,这道题转化了一波之后就会化成这个问题: ...
- HDU 6071 Lazy Running(很牛逼的最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=6071 题意: 1.2.3.4四个点依次形成一个环,现在有个人从2结点出发,每次可以往它相邻的两个结点跑,求最后回 ...
- HDU 6071 Lazy Running(最短路)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6071 [题目大意] 给出四个点1,2,3,4,1和2,2和3,3和4,4和1 之间有路相连, 现在 ...
- HDU 6071 同余最短路 spfa
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- 多校4 lazy running (最短路)
lazy running(最短路) 题意: 一个环上有四个点,从点2出发回到起点,走过的距离不小于K的最短距离是多少 \(K <= 10^{18} 1 <= d <= 30000\) ...
- 2017 Multi-University Training Contest - Team 4 hdu6071 Lazy Running
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6071 题目: Lazy Running Time Limit: 2000/1000 MS (J ...
随机推荐
- Eclipse 使用mybatis generator插件自动生成代码
Eclipse 使用mybatis generator插件自动生成代码 标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody{ paddin ...
- 图论&数学:最小平均值环
POJ2989:求解最小平均值环 最优化平均值的显然做法是01分数规划 给定一个带权有向图 对于这个图中的每一个环 定义这个环的价值为权值之和的平均值 对于所有的环,求出最小的平均值 这个结论怎么做的 ...
- C11关键字&字面值改善
1.原始字面值改善 原始字面值可以直接表示字符串的实际含义,但是一些特殊字符就需要转义. std::string str = "D:\A\B\test.txt"; std::cou ...
- 安装HDP时的报错信息
1,安装ambari时报错:Bootstrap process timed out. It will be destroyed. 报错原因:/etc/sudoers文件中未设置免密权限 解决办法:ha ...
- [CodePlus 2017 11月赛]晨跑 题解(辗转相除法求GCD)
[CodePlus 2017 11月赛]晨跑 Description "无体育,不清华"."每天锻炼一小时,健康工作五十年,幸福生活一辈子".在清华,体育运动绝 ...
- [网站安全] [实战分享]WEB漏洞挖掘的一些经验分享
WEB漏洞有很多种,比如SQL注入,比如XSS,比如文件包含,比如越权访问查看,比如目录遍历等等等等,漏洞带来的危害有很多,信息泄露,文件上传到GETSHELL,一直到内网渗透,这里我想分享的最主要的 ...
- 75.VS2013和opencv3.1.0开发环境配置
首先要做的就是 开发环境配置,具体过程如下: Step 1:OpenCV环境变量配置 我的电脑--->属性--->高级系统设置--->高级--->环境变量--->系统变量 ...
- (转)USB体系结构
转载地址:http://blog.ednchina.com/zenhuateng/203584/Message.aspx USB总线接口层:物理连接.电气信号环境.信息包传输机制:主机一方由USB主控 ...
- NoSQL-来自维基百科
NoSQL有时也称作Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统的统称. 两者存在许多显著的不同点,其中最重要的是NoSQL不使用SQL作为查询语言.其数据存储可以不需 ...
- 微信小程序开发定制
上海软件定制专家:http://www.dzonly.com/?from=timeline