E - Elevator
E - Elevator
http://codeforces.com/gym/241680/problem/E
同余最短路,从0~a-1中每一个i向(i+b)%a连一条权值为b的边,向(i+c)%a连一条权值为c的边,然后跑spfa最短路,此时d[i]表示达到x%a花费的最小的距离,这里放的只有b,c,(解释一下,b,c组合出的实际大小为x,因为x过大,数组存不下,所以表示为x%a
最后统计答案的时候ans+=1+(h-d[i])/a;当前只有b,c组合出的d[i]算一个答案,然后剩下可以用a来填充
//用最小的来做同余系比较快
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define INF 9187201950435737471
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
long long h;
long long a,b,c,ans;
long long d[];
queue<long long>q;
bool vis[]; struct node{
long long v;
long long n;
node *next;
}*e[]; void in(long long &x){
long long y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(long long x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} void push(long long x,long long y,long long v){
node *p;
p=new node();
p->n=y;
p->v=v;
if(e[x]==)
e[x]=p;
else{
p->next=e[x]->next;
e[x]->next=p;
}
} void spfa(){
For(i,,a)
d[i]=INF;
q.push(%a);
d[%a]=;
while(!q.empty()){
long long t=q.front();
q.pop();
vis[t]=true; for(node *i=e[t];i;i=i->next){
if(d[i->n]>d[t]+i->v){
d[i->n]=d[t]+i->v;
if(!vis[i->n]){
q.push(i->n);
vis[i->n]=true;
}
}
}
vis[t]=false;
}
} int main(){
freopen("elevator.in","r",stdin);
freopen("elevator.out","w",stdout);
in(h);
in(a);in(b);in(c);
if(a>b) swap(a,b);
if(a>c) swap(a,c);
For(i,,a-){
push(i,(i+b)%a,b);
push(i,(i+c)%a,c);
}
spfa();
For(i,,a-)
if(h>=d[i])
ans+=+(h-d[i])/a;
o(ans);
return ;
}
E - Elevator的更多相关文章
- HDOJ 1008. Elevator 简单模拟水题
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- poj[2392]space elevator
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- Design Elevator
From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9 ...
- PAT (Advanced Level) Practise:1008. Elevator
[题目链接] The highest building in our city has only one elevator. A request list is made up with N posi ...
- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]
作业提交时间:10月9日上课前. Design and implement an Elevator Scheduler to aim for both correctness and performa ...
- POJ2392Space Elevator(贪心+背包)
Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9970 Accepted: 4738 De ...
- hdu 1008 Elevator
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description The hig ...
- 【ACM】HDU1008 Elevator 新手题前后不同的代码版本
[前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...
- Elevator 分类: HDU 2015-06-19 21:52 13人阅读 评论(0) 收藏
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 1008. Elevator (20)
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
随机推荐
- IDEA 导入 Tomcat9 源码
源码下载(Source Code Distributions)地址:https://tomcat.apache.org/download-90.cgi tomcat 和 servlet 以及 jdk ...
- kubernetes包管理工具Helm安装
helm官方建议使用tls,首先生成证书. openssl genrsa -out ca.key.pem openssl req -key ca.key.pem -new -x509 -days -s ...
- Node.js目录
[相关学习] npm入门教程 [基础] (1) 初识Node.js (2) 开发环境和调试工具 (3) commonJs 规范 (4) node 概念(global.process进程.调试) (5) ...
- springboot springmvc拦截器 拦截POST、PUT、DELETE请求参数和响应数据,并记录操作日志
1.操作日志实体类 @Document(collection = "operation_log") @Getter @Setter @ToString public class O ...
- 如何用ps简单快速扣头发丝
好久不用PS抠图,今天接到一个小任务,换背景,以前一直用通道的办法,但用通道比较费劲,发现一个更简单的办法,就是用快速蒙版+调整边缘. 这张是原图: 1.先用快速蒙版制作选取(Q) 再按Q,退出快速蒙 ...
- 挖矿病毒、ddos入侵流程及溯源
一 挖矿病毒简介 攻击者利用相关安全隐患向目标机器种植病毒的行为. 二 攻击方式 攻击者通常利用弱口令.未授权.代码执行.命令执行等漏洞进行传播.示例如下: 示例1: POST /tmUnblo ...
- javascript浏览器事件
1. Js浏览器对象层级结构:Window 窗口对象(location地址对象.document文档对象(Form表单对象(表单控件))) 2. Window对象属性: 名称 描述 documen ...
- 不同IDE对maven项目静态资源处理
今天自己构建maven管理的web项目,参照另一位兄弟的代码,发现他的静态资源,也就是html.js之类的文件是在src/main/resource目录下的,我的在src/main/resource目 ...
- win10只有edge浏览器能上网的解决方法
问题描述:电脑就只有edge浏览器和自带的邮件可以上网,但是QQ Chrome,360浏览器都无法上网: 解决方法:打开命令提示符(管理员),执行netsh winsock reset,重启系统就好了 ...
- $(document).ready和window.onload的区别
$(document).ready比window.onload先执行.window.onload只执行一次. $(document).ready和window.onload都是在都是在页面加载完执行的 ...