多校4 lazy running (最短路)
lazy running(最短路)
题意: 一个环上有四个点,从点2出发回到起点,走过的距离不小于K的最短距离是多少 \(K <= 10^{18} 1 <= d <= 30000\)
看完这道题,觉得这是个智力题,想了一想,无从下手啊
每次总是看完题解,就豁然开朗
其实之前做过一个类似的题,题目
但是根本想不到第一步, 选2w来转换啊,而且也不知道正确性啊
这类题要仔细理解一番
#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
using namespace std;
const LL inf = 1e18;
const int N = 6e4 + 10;
int g[4][4];
int mod;
LL K;
LL dis[4][N];
int inq[4][N];
void spfa(){
for(int i = 0;i < 4;i++){
for(int j = 0;j < mod;j++) {
dis[i][j] = inf,inq[i][j] = 0;
}
}
queue<P> q;
dis[1][0] = 0,inq[1][0] = 0;
q.push(P(1,0));
while(!q.empty()){
P cur = q.front();q.pop();
for(int i = -1;i <= 2;i+=2){
int x = (cur.first + i + 4)%4, y = (cur.second + g[cur.first][x])%mod;
if(dis[x][y] > dis[cur.first][cur.second] + g[cur.first][x]){
dis[x][y]= dis[cur.first][cur.second] + g[cur.first][x];
if(!inq[x][y]){
inq[x][y] = 1;
q.push(P(x,y));
}
}
}
}
}
int main()
{
int T;
cin>>T;
while(T--){
cin>>K;
for(int i = 0;i < 4;i++) {
scanf("%d",&g[i][(i+1)%4]);
g[(i+1)%4][i] = g[i][(i+1)%4];
}
mod = 2 * min(g[0][1],g[1][2]);
spfa();
LL ans = 2e18;
for(int i = 0;i < mod;i++){
LL d = K - dis[1][i];
ans = min(ans, dis[1][i] + (d + mod - 1) / mod * mod);
}
printf("%lld\n",ans);
}
return 0;
}
多校4 lazy running (最短路)的更多相关文章
- 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 (同余最短路 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)To ...
- HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4
/* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...
- 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(很牛逼的最短路)
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 之间有路相连, 现在 ...
- 【最短路】【spfa】hdu6071 Lazy Running
给你一个4个点的环,问你从2号点出发, 再回到2号点,长度>=K的最短路是多少.环上的边长度不超过30000. 跑出来所有dis(2,j)以后,然后for一遍j,根据dis(2,j)+t*2*w ...
随机推荐
- springBoot支持PageHelp插件使用学习笔记
首先在springboot项目的maven中加入依赖(版本可能需要自己选择合适的) <dependency> <groupId>com.github.pagehelper< ...
- Spring Cloud 入门Eureka -Consumer服务消费(一)
这里介绍:LoadBalancerClient接口,它是一个负载均衡客户端的抽象定义,下面我们就看看如何使用Spring Cloud提供的负载均衡器客户端接口来实现服务的消费. 引用之前的文章中构建的 ...
- Linux问题分析或解决_ssh无法连接
1. ldd - 检查依赖库是否存在问题 问题:ssh连接不上,之前一直没有问题,最近别人安装了其他桌面(系统Ubuntu) 解决: 查看进程,发现没有启动 ps -ef | grep ssh 重新安 ...
- 内置函数系列之 map
map(映射函数)语法: map(函数,可迭代对象) 可以对可迭代对象中的每一个元素,分别执行函数里的操作 # 1.计算每个元素的平方 lst = [1,2,3,4,5] lst_new = map( ...
- HTML+CSS : H5+CSS3
HTML5语义化标签: header nav(导航) article section(章节) aside(侧边栏) footer------------------------------------ ...
- python__系统 : 线程
线程之间,全局变量可以共享,但是局部变量依然是不共享的,线程的创建方式: threading.Thread(),还可以定义一个类继承Thread,重写他的run方法,具体和进程的写法一样. 那么,线程 ...
- 学习Pytbon第十天 函数2 内置方法和匿名函数
print( all([1,-5,3]) )#如果可迭代对象里所有元素都为真则返回真.0不为真print( any([1,2]) )#如果数据里面任意一个数据为真返回则为真a= ascii([1,2, ...
- source tree 使用心得
SourceTree 是 Windows 和Mac OS X 下免费的 Git 和 Hg 客户端管理工具,同时也是Mercurial和Subversion版本控制系统工具.支持创建.克隆.提交.pus ...
- strchr函数的用法
原型: char *strchr(const char *s,char c); #include<string.h> 查找字符串s中首次出现字符c的位置,返回首次出现c的位置的指针,如果s ...
- C++ 二叉搜索树
二叉搜索树利用其特有的二叉树性质,使其搜索更方便 源代码: struct node { int val; node *left, *right; }; //the function of insert ...