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

Northeastern Europe 2007, Northern Subregion

题解

很神奇的构造方法。。

我们将所有楼层都对a取模,按余数分成a类

在每个分类中的楼层满足这样一个性质:

若有楼层x,y在同一类中且x<y那么如果x可达,y必可达

之后由于我们只需处理b,c两种连接方式即可

重点

我们每个同余类看成一个点(x)

枚举x 在\(x\)和\((x+b)%a、(x+c)%a\)之间连一条长度为b,c的边

之后从1开始跑最短路 得到 d[x]

此时d[x] 表示如何用最快的方式达到%a余x的楼层

显然,在这种情况下得到的d[x]还有一个含义便是能达到的%a余x的楼层的最小值

根据我们之前分析的同于类的性质可知满足\(d[x]+a^k (d[x]+a^k<=h)\)的所有楼层均能被达到

那么只需对所有同余类统计出的答案求和即可

code:(留坑)

[poj 3539] Elevator (同余类bfs)的更多相关文章

  1. poj 3539 Elevator——同余类bfs

    题目:http://poj.org/problem?id=3539 考虑把层数分为模a剩余系.同类内可通过+若干个a走到. 不同类之间需要通过+b.+c来走到. 需要求出每一类中最小的能走到的.即最短 ...

  2. poj3539 Elevator——同余类bfs

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

  3. [POJ] 3539 Elevator

    http://poj.org/problem?id=3539 给定一个电梯,可以上升a,b,c层和回到1层,给定楼高h,求可达层数 lyd讲的同余类BFS,方法是先把三个量压成两个,即把h%a,因为对 ...

  4. 同余类BFS的一些瞎吹

    同余类BFS的题,是个OIer基本上都会见过一些,最好的例子就是NOIP 2018 day1  T2---货币系统 虽然这题其实是什么背包就能解决的题目,但数据一变大,出题人坏一点,就没了.... 同 ...

  5. POJ 3539 Elevator(同余类BFS)

    题意 有一部电梯,最初停在1层. 电梯有4个按键,上升a,b,c层,回到一层. 求从一层出发.能到达1~h的哪些楼层. (h<=1018,a,b,c<=105) 题解 这种h能大的图论,一 ...

  6. BZOJ2118: 墨墨的等式(同余类BFS)(数学转为图论题)

    2118: 墨墨的等式 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2944  Solved: 1206[Submit][Status][Discu ...

  7. POJ 1324 Holedox Moving (状压BFS)

    POJ 1324 Holedox Moving (状压BFS) Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18091 Acc ...

  8. Luogu4156 WC2016 论战捆竹竿 KMP、同余类最短路、背包、单调队列

    传送门 豪华升级版同余类最短路-- 官方题解 主要写几个小trick: \(1.O(nm)\)实现同余类最短路: 设某一条边长度为\(x\),那么我们选择一个点,在同余类上不断跳\(x\),可以形成一 ...

  9. POJ.1426 Find The Multiple (BFS)

    POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...

随机推荐

  1. D - Mayor's posters

    D - Mayor's posters POJ - 2528 思路:线段树+离散化. 离散化时注意特殊情况,如果两个数相差大于一,离散时也应该差1.比如 1 3 离散后应该为 1 2. 错因: 1.二 ...

  2. Spring Boot 配置Oracle数据库

    1.添加oralce 依赖包,仓库没有则通过maven装载到本地仓库: 2.application.properties 中添加配置,特别是第一个配置项要严重注意! spring.jpa.databa ...

  3. 3.2 re--正則表達式操作(Regular expression operations)

    本模块提供了正則表達式的匹配操作,它的功能跟Perl语言里的功能一样. 不管是Unicode字符串还是单字节8位组成的字符串,都能够使用模式匹配和字符串查找的功能. 只是要注意的是Unicode字符串 ...

  4. 一种加快在苹果app store中上架的方法

    预计近期苹果app应用上架的比較多,审核比較慢,如今一个app从提交到上架短则7.8天.长则2.3个星期.我在实际上线应用时,总结了一个简单有用的小技巧,能够加快上架时间,近期使用这样的方法后.我们基 ...

  5. Android基础新手教程——3.4 TouchListener PK OnTouchEvent + 多点触碰

    Android基础新手教程--3.4 TouchListener PK OnTouchEvent + 多点触碰 标签(空格分隔): Android基础新手教程 本节引言: 如题,本节给大家带来的是To ...

  6. int*与(int*)的差别

    晚上被问到一个C++的问题: int **pa=new int* [5]; int *pb=new (int*)[5]; 上面两行代码的差别是什么? 分析与实验结果例如以下: (1)第一行代码能够在V ...

  7. selenium找到页面元素click没反应

    问题描述:通过调试可以看到控制台已经找到了起诉入口页面元素,可是点击“我是原告”没有反应了,也没有报错 解决办法:登录时是跳进了两层的iframe中,需要跳出iframe才能找到我是原告.

  8. 安装visual studio 2013【转】

    本文转载自:http://blog.csdn.net/tina_ttl/article/details/51544733#1下载-visual-studio-ultimate-2013安装包 微软已经 ...

  9. Python生成器实现杨辉三角打印

    def triangles(): c = [1] while 1: yield c a,b=[0]+c,c+[0] c=[a[i]+b[i] for i in range(len(a))] n = 0 ...

  10. jquery选择器(可见对象,不可见对象) +判断,对象(逆序)

    //可见对象: $("li:visible ") //可见对象下的 隐藏对象 $("li:visible [type='hidden']") //获得 可见 的 ...