POJ3539 Elevator

 
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开得不够大……
 1 /*by SilverN*/
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<queue>
 8 #define LL long long
 9 using namespace std;
10 const long long inf = 1000000000ll * 1000000000ll + 10ll;
11 const int mxn=100010;
12 int a[5];
13 LL h;
14 LL ans;
15 //
16 LL dis[mxn];
17 bool inq[mxn];
18 queue<int>q;
19 void SPFA(){
20     for(int i=0;i<a[1];i++)dis[i]=inf;
21     q.push(1%a[1]);
22     dis[1%a[1]]=1;
23     inq[1%a[1]]=1;
24     while(!q.empty()){
25         int now=q.front();q.pop();
26         
27         for(int i=2;i<=3;i++){
28             int v=(now+a[i])%a[1];
29             if(dis[v]>dis[now]+a[i]){
30                 dis[v]=dis[now]+a[i];
31                 if(!inq[v]){
32                     inq[v]=1;
33                     q.push(v);
34                 }
35             }
36         }
37         inq[now]=0;
38     }
39 }
40 int main(){
41     scanf("%lld%d%d%d",&h,&a[1],&a[2],&a[3]);
42     sort(a+1,a+3+1);
43     SPFA();
44     for(int i=0;i<a[1];i++){
45         if(dis[i]<=h)ans+=(h-dis[i])/a[1]+1;
46     }
47     printf("%lld\n",ans);
48     return 0;
49 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/5883599.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值