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. Python——print用法详解

    1.print语法格式 print()函数具有丰富的功能,详细语法格式如下:print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=Fa ...

  2. 01_8_Struts用DomainModel接收参数

    01_8_Struts用DomainModel接收参数 1. 配置struts.xml文件 <package name="user" namespace="/use ...

  3. Deepgreen DB 是什么(含Deepgreen和Greenplum下载地址)

    Deepgreen官网下载地址:http://vitessedata.com/products/deepgreen-db/download/ 不需要注册 Greenplum官网下载地址:https:/ ...

  4. vue 前端判断输入框不能输入0 空格。特殊符号。

    oninput="value=value.replace(/[^\d.]/g,'').replace(/\.{2,}/g,'.').replace('.','$#$').replace(/\ ...

  5. Django2.0里urls.py里配置的改变

    从Django2.0开始,urls.py配置方法有很大改变. 1.把url函数换成path 2.不在使用^.$作为路由 3.其他地方以后再进一步研究 下面看一个列子: from django.cont ...

  6. Docker 自动运行Nginx容器

    Dockerfile文件如下: FROM ubuntu #基础镜像 RUN apt-get update #更新apt RUN apt-get -y install nginx #安装nginx VO ...

  7. LeetCode1090. 受标签影响的最大值

    问题: 我们有一个项的集合,其中第 i 项的值为 values[i],标签为 labels[i]. 我们从这些项中选出一个子集 S,这样一来: |S| <= num_wanted 对于任意的标签 ...

  8. tp5使用外部类的三种方法

    在tp5中使用外部类的时候有三种方法 第一种就是通过composer下载,通过这种方式下载的外部类能够支持自动加载,我们只要在使用的时候use一下命名空间就可以使用了 比如:我们的tp5第四季项目要使 ...

  9. 有关fcrackzip的使用介绍(来自网络)

    本文转自:http://longxiaz.blog.163.com/blog/static/131452420201282844545197/ 主要用到的工具是fcrackzip.别的工具没去测试,f ...

  10. gcc——预处理(预编译),编译,汇编,链接

    一,预编译 操作步骤:gcc -E hello.c -o hello.i 主要作用: 处理关于 “#” 的指令 [1]删除#define,展开所有宏定义.例#define portnumber 333 ...