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. BootKit病毒——“异鬼Ⅱ”的前世今生

    七月底,一种名为"异鬼Ⅱ"的木马在全网大肆传播.一个多月过去了,风声渐渐平息,之前本来准备专门就这个木马写一篇博客的,结果拖到现在,幸好时间隔得还不算太久.闲话不多说,回到正题. ...

  2. 机器学习实战之 第10章 K-Means(K-均值)聚类算法

    第 10 章 K-Means(K-均值)聚类算法 K-Means 算法 聚类是一种无监督的学习, 它将相似的对象归到一个簇中, 将不相似对象归到不同簇中.相似这一概念取决于所选择的相似度计算方法.K- ...

  3. Spring详解(五)------AspectJ 实现AOP

    上一篇博客我们引出了 AOP 的概念,以及 AOP 的具体实现方式.但是为什么要这样实现?以及提出的切入点表达式到底该怎么理解? 这篇博客我们通过对 AspectJ 框架的介绍来详细了解. 1.什么是 ...

  4. 移动端图片放大滑动查看-插件photoswipe的使用

    最近在开发项目的时候,遇到一个需求,需要移动端实现放大查看图片的功能,然后我就在网上搜索了一下资料,看到了photoswipe这个插件,后来试了试,确实挺好用的,它可以实现手势放大缩小查看图片,左右滑 ...

  5. CCIE-MPLS VPN-实验手册(上卷)

    看完了看完了看完了,豪爽豪爽豪爽,一个月了,写得挺棒.总共14个mpls vpn的实验,为留下学习的痕迹,原封不动献出. CCIE实验手册 (路由部分-MPLSVPN基础篇) [CCIE]  JUST ...

  6. 个人作业-2 英语学习APP分析

    产品: 必应词典 PC版 第一部分:调研,评测 1.对于这款产品的第一感觉是界面做的有点生硬粗糙,而且界面有种很空的感觉,界面美化做的不是很好,第一印象不是很喜欢.不过一点,就是把单词的近义词反义词放 ...

  7. 第五次作业2、请将该code进行代码重构,使之模块化,并易于阅读和维护;

    1.请运行下面code,指出其功能: (需附运行结果截图,并用简短文字描述其功能) 显示了人的姓名.年龄 2.请将该code进行代码重构,使之模块化,并易于阅读和维护: 3.观看视频The Exper ...

  8. 201521123065《java程序设计》第8周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 1.Map通过get(key)来获取值: 2.HashMap和Hash ...

  9. 201521123029《Java程序设计》第七周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料:XMind 答: 2. 书面作业 1. ArrayList代码分析 1.1 解释ArrayList的contain ...

  10. 201521123014 《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 1.2 可选:使用常规方法总结其他上课内容. GUI与Sw ...