hdu 6071 Lazy Running 最短路建模
Lazy Running
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
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.
友情链接:https://post.icpc-camp.org/d/674-poi-x-sums
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-4
#define bug(x) cout<<"bug"<<x<<endl;
const int N=6e4+,M=1e6+,inf=1e9+,MOD=1e9+;
const LL INF=1e18+,mod=1e9+; struct mmp
{
int s;
LL dis;
bool operator <(const mmp &b)const
{
return dis>b.dis;
}
};
LL ans[][N];
int vis[][N];
priority_queue<mmp>q;
vector<pair<int,int> >edge[];
void dij(int s,int m)
{
ans[s][]=;
q.push((mmp){s,0LL});
while(!q.empty())
{
mmp now = q.top();
q.pop();
if(vis[now.s][now.dis%m])continue;
vis[now.s][now.dis%m]=;
for(int i = ; i < ; i++)
{
int v=edge[now.s][i].first;
int w=edge[now.s][i].second;
int z=(now.dis+w)%m;
if(ans[v][z]==-||ans[v][z] >=now.dis + w)
{
q.push((mmp){v,now.dis+w});
ans[v][z]=now.dis+w;
}
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(ans,-,sizeof(ans));
memset(vis,,sizeof(vis));
LL x;
int d1,d2,d3,d4;
scanf("%lld%d%d%d%d",&x,&d1,&d2,&d3,&d4);
for(int i=;i<=;i++)
edge[i].clear();
edge[].push_back(make_pair(,d1));
edge[].push_back(make_pair(,d4));
edge[].push_back(make_pair(,d1));
edge[].push_back(make_pair(,d2));
edge[].push_back(make_pair(,d3));
edge[].push_back(make_pair(,d2));
edge[].push_back(make_pair(,d3));
edge[].push_back(make_pair(,d4));
dij(,*d1);
LL out=INF;
d1*=;
for(int i=;i<d1;i++)
{
if(ans[][i]==-)continue;
if(ans[][i]>=x)out=min(out,ans[][i]);
else
{
LL z=x-ans[][i];
LL zz=ans[][i]+(z%d1?(z/d1+)*d1:z);
out=min(out,zz);
}
}
printf("%lld\n",out);
}
return ;
}
hdu 6071 Lazy Running 最短路建模的更多相关文章
- HDU 6071 Lazy Running (最短路)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6071 题解 又是一道虐信心的智商题... 首先有一个辅助问题,这道题转化了一波之后就会化成这个问题: ...
- HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4
/* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...
- 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(很牛逼的最短路)
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 之间有路相连, 现在 ...
- 多校4 lazy running (最短路)
lazy running(最短路) 题意: 一个环上有四个点,从点2出发回到起点,走过的距离不小于K的最短距离是多少 \(K <= 10^{18} 1 <= d <= 30000\) ...
- HDU 6071 同余最短路 spfa
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- 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 ...
随机推荐
- GUI编程实例
function varargout = GUI013(varargin) % GUI013 MATLAB code for GUI013.fig % GUI013, by itself, creat ...
- JustOj 1032: 习题6.7 完数
题目描述 一个数如果恰好等于它的因子之和,这个数就称为"完数". 例如,6的因子为1.2.3,而6=1+2+3,因此6是"完数". 编程序找出N之内的所有完数, ...
- [转载] 关于出现“使用 UNION、INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式”错误的可能原因
1. 对于该问题确实存在UNION前后SELECT语句中的列数不同导致:2. 以下为个人遇到的一种可能:在项目开发中由于有张表是动态的,即有个基础表,其他的表按年月根据基础表来生成动态表,动态表结构和 ...
- @Configuration与@Bean作用
Spring的Java配置方式是通过@Configuration和@Bean这两个注解来实现 @Configuration可以作用在任意类上,表示该类是一个配置类,其实就相当于一个xml配置文件. @ ...
- hiho一下 第144周
题目1 : 机会渺茫 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在追求一名学数学的女生小Z.小Z其实是想拒绝他的,但是找不到好的说辞,于是提出了这样的要求: ...
- com.sun.jersey.api.client.UniformInterfaceException:returned a response status of 403
这是在同一台电脑上,然后启动两台tomcat进行文件传输时候,会出现的一个异常. 403,是因为tomcat默认禁止上传,在tomcat中的config中的web.xml中进行以下的配置就可以进行文件 ...
- DBCP数据库连接池的使用
DBCP的简单介绍: DBCP(DataBase Connection Pool)数据库连接池,是java数据库连接池的一种,由apache开发通过数据库连接池可以让程序自动管理数据库连接的释放和断开 ...
- python-selenium,关于页面滑动的操作
//移动到元素element对象的“顶端”与当前窗口的“顶部”对齐 ((JavascriptExecutor) driver).executeScript("arguments[0].scr ...
- squid代理服务器安装和配置
服务器版本:centos6.5 squid版本:3.1 Squid介绍 Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用户想要下载一个主页时,可 ...
- http 请求头大小写的问题
如果是默认消息头名称,消息头格式已经固定,即便输入的大小写有误,也会给你翻译成默认的写法,如果自己定义的,会自动给你翻译成小写,所以传参数的名称都用小写字母即可,否则可能取不到值,比如encrypte ...