Elevator
Time Limit: 4000MS   Memory Limit: 65536K
Total Submissions: 1072   Accepted: 287
Case Time Limit: 2000MS

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 ab or c floors 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 ab and c — the parameters of the buttons (1 ≤ abc ≤ 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

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
ll bb[];
ll a,b,c;
priority_queue<ll,vector<ll>,greater<ll> > q;
void bfs()
{
while(!q.empty())q.pop();
q.push(+a),q.push(+b),q.push(+c);
ll d,i=;
while(!q.empty())
{
d=q.top();
q.pop();
if(bb[d%a]!=-&&bb[d%a]<=d)continue;
bb[d%a]=d;
i++;
if(i==a)return ;
q.push(d+b);
q.push(d+c);
}
}
int main()
{
ll h,ans;
ll i;
while(~scanf("%I64d",&h))
{
scanf("%I64d%I64d%I64d",&a,&b,&c);
if(a>b)swap(a,b);
if(a>c)swap(a,c);
memset(bb,-,sizeof(bb));
bfs();
ans=;
for(i=; i<a; i++)
{
// cout<<bb[i]<<" ";
if(bb[i]==-||h<bb[i])continue;
ans+=(h-bb[i]+)/a;
if((h-bb[i]+)%a)ans++;
}
// cout<<endl;
printf("%I64d\n",ans+);
}
}

Elevator poj3539的更多相关文章

  1. POJ3539 Elevator

    Time Limit: 4000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Description Edward wor ...

  2. poj3539 Elevator——同余类bfs

    题目:http://poj.org/problem?id=3539 题目大意是给定 a, b, c,求 1~h 内有多少个数可以被 a, b, c 通过加减法组成: 这是今天刚讲的神奇的——同余类 b ...

  3. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. poj[2392]space elevator

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  5. Design Elevator

    From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9 ...

  6. 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 ...

  7. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]

    作业提交时间:10月9日上课前. Design and implement an Elevator Scheduler to aim for both correctness and performa ...

  8. POJ2392Space Elevator(贪心+背包)

    Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9970   Accepted: 4738 De ...

  9. hdu 1008 Elevator

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The hig ...

随机推荐

  1. 一台电脑 一起跑python2 python3

    我习惯使用python2.7,命令都是使用的python和pip,这时候装了python3.4,首先到python3下修改python.exe,pythonw.exe为python3.exe,pyth ...

  2. 【 DCOS 】织云 CMDB 管理引擎技术详解

    欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者 : 李琦 , 腾讯高级工程师 , 就职于网络平台部.曾负责公司海量运营系统的规划设计,如 TMP.Sniper.GSLB.IDCSp ...

  3. 搭建互联网DNS构架

    author:JevonWei 版权声明:原创作品 构建"." DNS."com" DNS及"danran.com",用户通过"电 ...

  4. Centos 6 PXE安装

    author:JevonWei 版权声明:原创作品 192.168.198.134作为安装服务器,由httpd服务共享安装程序 192.168.198.134作为dhcp服务器,客户机获取IP 一.安 ...

  5. MySQL(七)MySQL常用函数

    前言 上一篇给大家介绍了,MySQL常用的操作符其实已经是非常的详细了,现在给大家分享的是MySQL的常用函数.希望对我和对大家都有帮助. 一.字符串函数 1.1.LOWER.lcase(string ...

  6. Ajax异步请求模板

    $.ajax({ url: '', type: 'post', data: {'id':id}, dataType: 'json', success: function(data,statusText ...

  7. 在Android上仿百度贴吧客户端Loading图标小球

    封面 前言 使用百度贴吧客户端的时候发发现加载的小动画挺有意思的,于是自己动手写写看.想学习自定义View以及自定义动画的小伙伴一定不要错过哦. 读者朋友需要有最基本的canvas绘图功底,比如画笔P ...

  8. JS常用方法总结

    1.javascript删除元素节点 IE中有这样一个方法:removeNode(),这个方法在IE下是好使的,但是在Firefox等标准浏览器中就会报错了 removeNode is not def ...

  9. poj 1200字符串hash

    题意:给出不同字符个数和子串长度,判断有多少个不同的子串 思路:字符串hash. 用字符串函数+map为什么会超时呢?? 代码: #include <iostream> #include ...

  10. 使用JSR-303进行校验 @Valid

    一.在SringMVC中使用 使用注解 1.准备校验时使用的JAR validation-api-1.0.0.GA.jar:JDK的接口: hibernate-validator-4.2.0.Fina ...