POJ3539 Elevator
Time Limit: 4000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
Edward works as an engineer for Non-trivial Elevators: Engineering, Research and Construction (NEERC). His new task is to design a brand new elevator for a skyscraper with h floors.
Edward has an idée fixe: he thinks that four buttons are enough to control the movement of the elevator. His last proposal suggests the following four buttons:
- Move a floors up.
- Move b floors up.
- Move c floors up.
- Return to the first floor.
Initially, the elevator is on the first floor. A passenger uses the first three buttons to reach the floor she needs. If a passenger tries to move a, b or cfloors up and there is no such floor (she attempts to move higher than the h-th floor), the elevator doesn’t move.
To prove his plan worthy, Edward wants to know how many floors are actually accessible from the first floor via his elevator. Help him calculate this number.
Input
The first line of the input file contains one integer h — the height of the skyscraper (1 ≤ h ≤ 1018).
The second line contains three integers a, b and c — the parameters of the buttons (1 ≤ a, b, c ≤ 100 000 ).
Output
Output one integer number — the number of floors that are reachable from the first floor.
Sample Input
15
4 7 9
Sample Output
9
Source
/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define LL long long
using namespace std;
const long long inf = 1000000000ll * 1000000000ll + 10ll;
const int mxn=;
int a[];
LL h;
LL ans;
//
LL dis[mxn];
bool inq[mxn];
queue<int>q;
void SPFA(){
for(int i=;i<a[];i++)dis[i]=inf;
q.push(%a[]);
dis[%a[]]=;
inq[%a[]]=;
while(!q.empty()){
int now=q.front();q.pop(); for(int i=;i<=;i++){
int v=(now+a[i])%a[];
if(dis[v]>dis[now]+a[i]){
dis[v]=dis[now]+a[i];
if(!inq[v]){
inq[v]=;
q.push(v);
}
}
}
inq[now]=;
}
}
int main(){
scanf("%lld%d%d%d",&h,&a[],&a[],&a[]);
sort(a+,a++);
SPFA();
for(int i=;i<a[];i++){
if(dis[i]<=h)ans+=(h-dis[i])/a[]+;
}
printf("%lld\n",ans);
return ;
}
POJ3539 Elevator的更多相关文章
- poj3539 Elevator——同余类bfs
题目:http://poj.org/problem?id=3539 题目大意是给定 a, b, c,求 1~h 内有多少个数可以被 a, b, c 通过加减法组成: 这是今天刚讲的神奇的——同余类 b ...
- Elevator poj3539
Elevator Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 1072 Accepted: 287 Case Time ...
- 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 ...
随机推荐
- Java字符串池(String Pool)深度解析(转)
出自 http://www.cnblogs.com/fangfuhai/p/5500065.html 在工作中,String类是我们使用频率非常高的一种对象类型.JVM为了提升性能和减少内存开销,避 ...
- Dede技巧
解决DEDE图集上传图片时跳出302错误 本地上传图集的时候突然提示网页出错,还爆出302错误. 解决办法是在include/userlogin.class.php文件中的第二行session_s ...
- 学习JavaScript你必须掌握的8大知识点!
大知识点! 一.JavaScript思维导图之<变量>的学习 二. JavaScript思维导图之<函数基础> 三.JavaScript思维导图之<基本dom操作 ...
- ios 设计模式总结
设计模式:备注:消息传递模型(Message Passing)是Objective-C语言的核心机制.在Objective-C中,没有方法调用这种说法,只有消息传递.在C++或Java中调用某个类的方 ...
- 【启发式搜索】Codechef March Cook-Off 2018. Maximum Tree Path
有点像计蒜之道里的 京东的物流路径 题目描述 给定一棵 N 个节点的树,每个节点有一个正整数权值.记节点 i 的权值为 Ai.考虑节点 u 和 v 之间的一条简单路径,记 dist(u, v) 为其长 ...
- Linux中nginx的常见指令
1.启动cd /usr/local/nginxsbin/nginx 版权声明:本文为博主原创文章,未经博主允许不得转载. 原文地址: https://www.cnblogs.com/poterliu/ ...
- 4.layhm框架初始化准备Init
hm\core\Boot 里 Boot 里run() 自动开起session 设置时区 <?php /** * Created by Haima. * Author:Haima * QQ:228 ...
- 在ArchLinux、manjaro中安装MySql(mariaDB)
安装MySql数据库.但是在MySql被Oracle收购之后,很多开源支持者就转而使用MariaDb了.不过MariaDb也和MySql兼容的,所以基本不用有什么担心.由于ArchLinux只带了Ma ...
- graph-basic
打算使用STL中的vector,通过邻接链表的方式存储图.这里贴基本定义,以及depth-first-search和breadth-first-search的实现代码. 其他图的算法实现,就贴在各自的 ...
- Java策略模式(Strategy)
一.定义 定义一组算法,将每个算法都封装起来,并且使它们之间可以互换.策略模式使这些算法在客户端调用它们的时候能够互不影响地变化.(Java的TreeSet集合中,构造方法可传入具体的比较器对象以实现 ...