Elevator poj3539

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

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <math.h>
 5 #include <vector>
 6 #include <queue>
 7 using namespace std;
 8 #define ll long long
 9 ll bb[110000];
10 ll a,b,c;
11 priority_queue<ll,vector<ll>,greater<ll> > q;
12 void bfs()
13 {
14     while(!q.empty())q.pop();
15     q.push(1+a),q.push(1+b),q.push(1+c);
16     ll d,i=0;
17     while(!q.empty())
18     {
19         d=q.top();
20         q.pop();
21         if(bb[d%a]!=-1&&bb[d%a]<=d)continue;
22         bb[d%a]=d;
23         i++;
24         if(i==a)return ;
25         q.push(d+b);
26         q.push(d+c);
27     }
28 }
29 int main()
30 {
31     ll h,ans;
32     ll i;
33     while(~scanf("%I64d",&h))
34     {
35         scanf("%I64d%I64d%I64d",&a,&b,&c);
36         if(a>b)swap(a,b);
37         if(a>c)swap(a,c);
38         memset(bb,-1,sizeof(bb));
39         bfs();
40         ans=0;
41         for(i=0; i<a; i++)
42         {
43 //            cout<<bb[i]<<" ";
44             if(bb[i]==-1||h<bb[i])continue;
45             ans+=(h-bb[i]+1)/a;
46             if((h-bb[i]+1)%a)ans++;
47         }
48 //        cout<<endl;
49         printf("%I64d\n",ans+1);
50     }
51 }

时间: 2024-08-04 03:52:42

Elevator poj3539的相关文章

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 skyscrap

「POJ3539」Elevator - 同余类最短路

->戳我进原题 Elevator Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 1572 Accepted: 424 Case Time Limit: 2000MS Description Edward works as an engineer for Non-trivial Elevators: Engineering, Research and Construction (NEERC). His new task is

Elevator

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will s

hdu 1008 elevator

#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n; while(~scanf("%d",&n)&&n!=0) { int a,b; a=0; int ans=0; for(int i=0;i<n;i++) { scanf("

poj 2392 Space Elevator (多重背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8110   Accepted: 3843 题目大意  :一群牛要上天  用一些石块堆塔  给出石块的种类  及其每个种类的数量 和该种石块能出现的最高高度  和每种石块的数量 求怎么摆放才能堆得最高 多重背包模板题.... 将所有石块排序  把高度低的放下面 #include<iostream> #include<cstdio>

POJ2392Space Elevator(贪心+背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9970   Accepted: 4738 Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <

poj 2392 Space Elevator(多重背包+先排序)

Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h

XTUOJ 1206 Dormitory&#39;s Elevator

Dormitory's Elevator Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The new dormitory has N(1≤N≤100000) floors and M(1≤M≤100000)students. In the new dormitory, in order to save student's time as well as encourage student exercise,

1008. Elevator

The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seco