zoukankan      html  css  js  c++  java
  • bzoj:1665 [Usaco2006 Open]The Climbing Wall 攀岩

    Description

    One of the most popular attractions at the county fair is the climbing wall. Bessie wants to plan her trip up the wall in advance and needs your help. The wall is 30,000 millimeters wide and H (1001 <= H <= 30,000) millimeters high and has F (1 <= F <= 10,000) hoof-holds at unique X,Y coordinates expressed in millimeters. 0,0 is at the ground level on the left side of the wall. Hoof-holds are separated by at least 300 millimeters since no cow can maneuver them if they are spaced too close! Bessie knows there is at least one way up. Bessie, through techniques only she knows, uses successive single hoof-holds to climb the wall. She can only move from one hoof-hold to another if they are no more than one meter apart. She can, of course, move up, down, right, left or some combination of these in each move. Similarly, once she gets to a hoof-hold that is at least H-1000 millimeters above the ground, she can nimbly climb from there onto the platform atop the wall. Bessie can start at any X location that has a Y location <= 1000 millimeters. Given the height of the wall and the locations of the hoof-holds, determine the smallest number of hoof-holds Bessie should use to reach the top.

    Bessie参加了爬墙比赛,比赛用的墙宽30000,高H(1001 <= H <= 30,000)。墙上有F(1 <= F <= 10,000)个不同的落脚点(X,Y)。 (0,0)在左下角的地面。所有的落脚点至少相距300。Bessie知道至少有一条路可以上去。 Bessie只能从一个落脚点爬到另一个距离不超过1000的落脚点,她可以向上下左右四个方向爬行。同样地,一旦她到达了一个高度 至少有H-1000的落脚点,她可以敏捷地爬到墙顶上。Bessie一开始可以在任意一个高度不超过1000的落脚点上。问Bessie至少攀爬多少次.这里两个点的距离都是欧几里得距离

    Input

    * Line 1: Two space-separated integers, H and F.

    * Lines 2..F+1: Each line contains two space-separated integers (respectively X and Y) that describe a hoof-hold. X is the distance from the left edge of the climbing wall; Y is the distance from the ground.

    Output

    * Line 1: A single integer that is the smallest number of hoof-holds Bessie must use to reach the top of the climbing wall.

    Sample Input

    3000 5
    600 800
    1600 1800
    100 1300
    300 2100
    1600 2300

    INPUT DETAILS:

    The wall is three meters high with 5 hoof-holds.

    Sample Output

    3
     
     
     
    直接暴力上……
    #include<queue>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
     
    struct na{
        int x,y;
    };
    struct ma{
        int x,y,q;
    };
    int n,m,x,l[30001],r[30001],dis[10001],j;
    na b[10001];
    char c;
    queue <ma> q;
    bool cmp(na a,na b){
        if (a.x==b.x) return a.y<b.y;
        return a.x<b.x;
    }
    bool able(ma a,na b){
        int lx=a.x-b.x,ly=a.y-b.y;
        if (lx*lx+ly*ly<=1000000) return 1;else return 0;
    }
    int read(){
        x=0;c=getchar();
        while(c<'0'||c>'9') c=getchar();
        while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
        return x;
    }
    int main(){
        n=read();m=read();
        for (int i=1;i<=m;i++){
            b[i].x=read(),b[i].y=read();
            if (b[i].y<=1000){
                ma tmp;
                tmp.x=b[i].x;
                tmp.y=b[i].y;
                tmp.q=1;q.push(tmp);
            }
            dis[i]=10000000;
        }
        sort(b+1,b+m+1,cmp);
        for (int i=1;i<=m;i++)
        if (l[b[i].x]==0) l[b[i].x]=i,r[b[i-1].x]=i-1;
        l[30000]=m+1;
        r[0]=1;
        r[b[m].x]=m;
        for (int i=0;i<=30000;i++) if (r[i]==0) r[i]=r[i-1];
        for (int i=30000;i>=0;i--) if (l[i]==0) l[i]=l[i+1];
        while(!q.empty()){
            ma k=q.front();q.pop();
            j=r[min(k.x+1000,n)];
            for (int i=l[max(k.x-1000,0)];i<=j;i++){
                if (!able(k,b[(i+r[b[i].x]+1)>>1])&&b[(i+r[b[i].x]+1)>>1].y<k.y&&i<=((i+r[b[i].x]+1)>>1)) i=((i+r[b[i].x]+1)>>1)+1;
                if (!able(k,b[(i+r[b[i].x]+1)>>1])&&b[(i+r[b[i].x]+1)>>1].y<k.y&&i<=((i+r[b[i].x]+1)>>1)) i=((i+r[b[i].x]+1)>>1)+1;
                if (able(k,b[i])){
                    if (dis[i]>k.q+1){
                            if (b[i].y>=n-1000){
                               printf("%d
    ",k.q+1);
                                return 0;
                            }
                            dis[i]=k.q+1;
                            ma tmp;tmp.x=b[i].x;tmp.y=b[i].y;tmp.q=dis[i];
                            q.push(tmp);
                    }
                }else
                if (b[i].y>=k.y) i=l[b[i].x+1]-1;
            }
        }
    }
  • 相关阅读:
    windows服务的默认启动类型和登录帐户
    oracle通过sql随机取表中的10条记录
    oracle如何四舍五入?
    Sql Server数据库自增长字段标识列的插入或更新修改操作办法
    将一个表中的数据导入到另一张表中
    设计模式已经陨落了?
    LINQ架构简单描述
    Asp.Net 验证控件
    .Net 三层架构开发初步
    C++编程思想
  • 原文地址:https://www.cnblogs.com/Enceladus/p/5011471.html
Copyright © 2011-2022 走看看