poj 3539 Elevator

Elevator

Time Limit: 4000MS Memory Limit: 65536K
Total Submissions: 1285 Accepted: 342
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 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


【分析】
不想分析,都是套路。WA到迷醉,只能抄袭。


【代码】

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
const long long inf = 1000000000ll * 1000000000ll + 10ll;
queue<int>q;
bool vis[100005];
long long h,ans,dis[100005];
int a,b,c;
int main()
{
    scanf("%lld%d%d%d",&h,&a,&b,&c);
    if(a>b)
        swap(a,b);
    if(a>c)
        swap(a,c);
    for(int i=0;i<=a-1;i++)
        dis[i]=inf;
    dis[1%a]=1;
    q.push(1%a);
    vis[1%a]=1;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        if(dis[(u+b)%a]>dis[u]+b)
        {
            dis[(u+b)%a]=dis[u]+b;
            if(!vis[(u+b)%a])
            {
                vis[(u+b)%a]=1;
                q.push((u+b)%a);
            }
        }
        if(dis[(u+c)%a]>dis[u]+c)
        {
            dis[(u+c)%a]=dis[u]+c;
            if(!vis[(u+c)%a])
            {
                vis[(u+c)%a]=1;
                q.push((u+c)%a);
            }
        }
        vis[u]=0;
    }
    for(int i=0;i<=a-1;++i)
        if(dis[i]<=h)
            ans+=(h-dis[i])/a+1;
    printf("%lld\n",ans);
    return 0;
}

【WA代码】

//poj 
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll long long
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
ll dis[100005],q[100005];
bool vis[100005];
ll a,b,c,H,ans;
int main()
{
    int i,j,u,v;
    scanf("%lld%lld%lld%lld",&H,&a,&b,&c);
    if(a>b) swap(a,b);
    if(a>c) swap(a,c);
    H--;
    if(a>H) {printf("1\n");return 0;}
    fo(i,0,100000) dis[i]=1e18;
    dis[0]=0;
    q[1]=0;vis[0]=1;
    ll h=0,t=1;
    while(h<t)
    {
        u=q[++h];
        v=(u+b)%a;
        if(dis[v]>dis[u]+b)
        {
            if(dis[u]+b<=H) dis[v]=dis[u]+b;
            if(!vis[v]) vis[v]=1,q[++t]=v;
        }
        v=(u+c)%a;
        if(dis[v]>dis[u]+c)
        {
            if(dis[u]+c<=H) dis[v]=dis[u]+c;
            if(!vis[v]) vis[v]=1,q[++t]=v;
        }
    }
    fo(i,1,a-1)
      if(dis[i]<=H)
        ans+=dis[i]/a;
      else
      {
        if((H%a)<i) ans+=H/a;
        else ans+=H/a+1;
      }
    printf("%lld\n",H+1-ans);
    return 0;
}
//21
//6 7 9

我真不知道哪里挂了。心好累

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值