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 ab 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 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

Source

Northeastern Europe 2007, Northern Subregion
 
同余类BFS
http://blog.csdn.net/rlt1296/article/details/52573529
↑这里讲得挺好。
 
WA了20分钟,发现INF开得不够大……
 /*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的更多相关文章

  1. poj3539 Elevator——同余类bfs

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

  2. Elevator poj3539

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

  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. JQuery EasyUI学习记录(一)

    1.主页设计(JQuery EasyUI插件) 下载easyUI开发包: 将easyUI资源文件导入页面中: <link rel="stylesheet" type=&quo ...

  2. Race condition

    在很多门课上都接触到race condition, 其中也举了很多方法解决这个问题.于是想来总结一下这些方法. Race condition 它旨在描述一个系统或者进程的输出依赖于不受控制的事件出现顺 ...

  3. 我的offer之路(一)

    目录 1.职业规划. 2.刷题. 3.看书. <剑指offer> <数据结构算法与应用:C++语言描述 > <Effective C++> <C与指针> ...

  4. Springboot @Autowired 无法注入问题

    特别提醒:一定要注意文件结构 WebappApplication 一定要在包的最外层,否则Spring无法对所有的类进行托管,会造成@Autowired 无法注入. 1. 添加工具类获取在 Sprin ...

  5. Linux菜鸟起飞之路【九】系统启动流程

    Linux系统启动流程 BIOS -> MBR  -> BootLoader -> Kernel -> init 1.打开电源后,计算机从主板的BIOS中读取其中存储的程序.这 ...

  6. 【整理】虚拟机和主机ping不通解决办法,虚拟机ping不通外网的解决方法

     检查几个方面: 1.检查虚拟网卡有没有被禁用2.检查虚拟机与物理机是否在一个VMNet中3.检查虚拟机的IP地址与物理机对应的VMNet是否在一个网段4.检查虚拟机与物理机的防火墙是否允许PING, ...

  7. supervisor 安装使用

     简介 Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启.它是通过fork/exec的方式把这些被管 ...

  8. LeetCode(258) Add Digits

    题目 Given a non-negative integer num, repeatedly add all its digits until the result has only one dig ...

  9. 使用powershell/vbs自动化模拟鼠标点击操作

    今天想做windows上的自动化,所以才有了模拟鼠标点击的需求,先考虑用powershell实现: 首先先安装一个名为“WASP”免费可用的Powershell扩展程序,下载地址:http://was ...

  10. python multiprocessing 源码分析

    1. 文档是最先需要了解的,读完文档可能会有很多的意外的收获同时也会留下疑惑,对于一般的使用我觉得读完文档就差不多了,除非一些很有疑惑的地方你可能需要再深入的了解一下.我读文档的目的第一个就是为了找出 ...