【最短路】【spfa】hdu6071 Lazy Running
给你一个4个点的环,问你从2号点出发, 再回到2号点,长度>=K的最短路是多少。环上的边长度不超过30000。

跑出来所有dis(2,j)以后,然后for一遍j,根据dis(2,j)+t*2*w>=K,解出来对于每个j而言最小的t,然后尝试更新答案即可。如果dis(2,j)已经大于等于K了,那直接用其尝试更新答案。
跟CDOJ1633很像。
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
ll ans,K;
int W,T,a[4];
typedef pair<int,int> Point;
queue<Point>q;
bool inq[4][60010];
int dis[4][60010];
void spfa()
{
memset(dis,0x7f,sizeof(dis));
memset(inq,0,sizeof(inq));
q.push(make_pair(1,0)); inq[1][0]=1; dis[1][0]=0;
while(!q.empty()){
Point U=q.front();
Point V=make_pair((U.first+1)%4,(U.second+a[U.first])%(2*W));
if(dis[V.first][V.second]>dis[U.first][U.second]+a[U.first]){
dis[V.first][V.second]=dis[U.first][U.second]+a[U.first];
if(!inq[V.first][V.second]){
q.push(V);
inq[V.first][V.second]=1;
}
}
V=make_pair((U.first+3)%4,(U.second+a[(U.first+3)%4])%(2*W));
if(dis[V.first][V.second]>dis[U.first][U.second]+a[(U.first+3)%4]){
dis[V.first][V.second]=dis[U.first][U.second]+a[(U.first+3)%4];
if(!inq[V.first][V.second]){
q.push(V);
inq[V.first][V.second]=1;
}
}
q.pop();
inq[U.first][U.second]=0;
}
}
int main(){
// freopen("1005.in","r",stdin);
// freopen("1005.out","w",stdout);
scanf("%d",&T);
for(;T;--T){
ans=9000000000000000000ll;
scanf("%lld",&K);
for(int i=0;i<4;++i){
scanf("%d",&a[i]);
}
W=min(a[1],a[0]);
spfa();
for(int i=0;i<2*W;++i){
if(dis[1][i]<2000000000){
// printf("%d: (%d)\n",i,dis[1][i]);
if(dis[1][i]<K){
ans=min(ans,(ll)dis[1][i]+(ll)(2*W)*((K-(ll)dis[1][i])/(ll)(2*W)+(ll)((K-(ll)dis[1][i])%(ll)(2*W)!=0)));
}
else{
ans=min(ans,(ll)dis[1][i]);
}
}
}
printf("%lld\n",ans);
}
return 0;
}
【最短路】【spfa】hdu6071 Lazy Running的更多相关文章
- 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 ...
- hdu-6071 Lazy Running
In HDU, you have to run along the campus for 24 times, or you will fail in PE. According to the rule ...
- HDU 6071 Lazy Running (同余最短路)
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\) ...
- HDU 6071 Lazy Running (同余最短路 dij)
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 | 2017 Multi-University Training Contest 4
/* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...
- 最短路模板(Dijkstra & Dijkstra算法+堆优化 & bellman_ford & 单源最短路SPFA)
关于几个的区别和联系:http://www.cnblogs.com/zswbky/p/5432353.html d.每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个(草儿家到 ...
- HDU 6071 同余最短路 spfa
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
随机推荐
- js_微信分享,监听点击分享,分享成功,取消分享,分享失败回调
2017-06-13 见代码: function weixinShare() { var links = links = "www.youku.com"; common.get_o ...
- Apache2.4+Tomcat7 集群
Apache2.4+Tomcat7 集群: 1.下载并安装相对应的软件 apache下载地址:http://httpd.apache.org/ 这里使用apache2.4 tomcat下载地址:htt ...
- perl6中函数参数(2)
use v6; #如果参数是可选的, 可以在后面加个?后定义 sub Choo($x, $y?){ say $x+$y; } Choo(); Choo(,); #具名参数, 也就是字典形式的调用 su ...
- 寻找kernel32.dll的地址
为了寻找kernel32.dll的地址,可以直接输出,也可以通过TEB,PEB等查找. 寻找TEB: dt _TEB nt!_TEB +0x000 NtTib : _NT_TIB +0x01c Env ...
- Python3安装Celery模块后执行Celery命令报错
1 Python3安装Celery模块后执行Celery命令报错 pip3 install celery # 安装正常,但是执行celery 命令的时候提示没有_ssl模块什么的 手动在Python解 ...
- python基础===zmail,收发邮件的模块
项目地址: GitHub:https://github.com/ZYunH/zmail 介绍: https://mp.weixin.qq.com/s?__biz=MzAxMjUyNDQ5OA==&a ...
- monkey测试===如何获取android app的Activity
方法一(推荐): 手机连接adb,手机界面在需要取得activity的界面. 推荐使用该命令: adb shell dumpsys activity top | findstr ACTIVITY 获取 ...
- Microsoft Security Essential: 微软安全软件
Microsoft Security Essential: 微软安全软件 这个杀毒软件终身免费
- 【bzoj1024】生日蛋糕
一开始想dp 后来发现既然要均等,又看了下数据条件 暴力就能做. #include<bits/stdc++.h> using namespace std; ; int x,y,n; dou ...
- 【Educational Codeforces Round 19】
这场edu蛮简单的…… 连道数据结构题都没有…… A.随便质因数分解凑一下即可. #include<bits/stdc++.h> #define N 100005 using namesp ...