/ Vijos / 讨论 / 分享 /

奇怪的电梯

呵呵,有一天 Peter 做了一个梦,梦见了一种很奇怪的电梯。大楼的每一层楼都可以停电梯,而且第i层楼(1

4 条评论

  • @ 2017-03-28 20:09:15

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    int n,a,b;
    int l[10000];
    int dg(int x)
    {
    if(x==b)return 1;
    else
    {
    if(x+l[x]<b&&x-l[x]>=1)
    {
    return x+l[x]||x-l[x];
    }
    if(x-l[x]<1&&x+l[x]<b)
    {
    return x+l[x];
    }
    if(x-l[x]>=1&&x+l[x]>b)
    {
    return x-l[x];
    }
    else
    {
    return 9999;
    }
    }
    }
    int main()
    {
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
    cin>>l[i];
    }
    int q=dg(l[a]+1);
    if(q==9999)
    {
    cout<<"-1";
    }
    else cout<<q+1;
    }

  • @ 2016-11-16 19:31:27

    深搜都可~
    ```pascal
    program lift;
    uses math;
    var n,a,b,i,ans,step:longint;
    s:array[1..200]of longint;
    qwq:array[1..200]of boolean;

    procedure dfs(v:longint);
    begin
    if step>ans then exit;
    if v=b then begin ans:=min(step,ans);exit;end;
    inc(step);qwq[v]:=false;
    if (v-s[v]>=1)and(qwq[v-s[v]]) then
    begin
    dfs(v-s[v]);
    end;
    if (v+s[v]<=n)and(qwq[v+s[v]]) then
    begin
    dfs(v+s[v]);
    end;
    dec(step);qwq[v]:=true;
    end;

    begin
    readln(n,a,b);
    for i:=1 to n do read(s[i]);

    ans:=maxlongint;step:=0;
    fillchar(qwq,sizeof(qwq),true);
    dfs(a);

    if ans=maxlongint then writeln(-1)
    else writeln(ans);
    end.
    ```

  • @ 2010-04-15 19:35:00

    = =

    DP,最短路,甚至BFS即可。。。。

  • @ 2010-04-14 17:37:29

    var n,i,j,x,y,t,w,p:longint;

    q:array[0..4000] of record

    dep,pr:longint;

    end;

    a:array[1..200] of longint;

    b:array[1..200] of boolean;

    yy:boolean;

    begin

    assign(input,'LIFT.IN');

    assign(output,'LIFT.OUT');

    reset(input);rewrite(output);

    readln(n,x,y);

    for i:=1 to n do read(a[i]);

    if x=y then begin writeln(0); close(input);close(output); halt;end;{close~~}

    fillchar(b,sizeof(b),true);

    b[x]:=true;

    q[1].dep:=x;q[1].pr:=0;

    t:=1;w:=1;

    while t

  • 1