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 ...
随机推荐
- Forbidden You don't have permission to access /phpStudyTest/application/index/controller/Index.php on this server.
发生情况:将thinkPHP从官网上下了 http://thinkphp.cn 然后安装了phpstudy和PHPstorm,并将thinkPHP解压到www路径下 在用PHPstorm打开 thi ...
- Flash as3.0 保存MovieClip运动轨迹到json文件
//放在第一帧调用 import flash.events.Event; import flash.display.MovieClip; stage.addEventListener(Event.EN ...
- iOS或Mac开发者应该记住的前缀
- NOIP模拟赛 czy的后宫4
czy的后宫4 [问题描述] czy有很多妹子,妹子虽然数量很多,但是质量不容乐观,她们的美丽值全部为负数(喜闻乐见). czy每天都要带N个妹子到机房,她们都有一个独一无二的美丽值,美丽值为-1到- ...
- (74)zabbix第三方认证之http(nginx basic auth)
HTTP Basic Auth认证方式,我们将在实例中使用nginx来演示,Apache也类似. zabbix认证配置 Administration>> Authentication,将h ...
- Powershell 备忘
如何修改环境变量 [environment]::SetEnvironmentvariable(“path”,"xxx","user") [environment ...
- LeetCode(232) Implement Queue using Stacks
题目 Implement the following operations of a queue using stacks. push(x) – Push element x to the back ...
- 【HIHOCODER 1420】 Bigint Multiplication
描述 Given 2 nonnegative integers a and b, calculate a × b. 输入 One line with 2 integers a and b separa ...
- Mysql中的联合索引、前缀索引、覆盖索引
索引 索引是一种特殊的文件,它们包含着对数据表里所有记录的引用指针.更通俗的说,数据库索引好比是一本书前面的目录,能加快数据库的查询速度. 联合索引 又名复合索引,由两个或多个列的索引.它规定了mys ...
- lwqq
源码安装lwqq 加密保存密码 发送截图