码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj:1665: [Usaco2006 Open]The Climbing Wall 攀岩

时间:2015-12-01 23:05:56      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:

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\n",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;
        }
    }
}

 

bzoj:1665: [Usaco2006 Open]The Climbing Wall 攀岩

标签:

原文地址:http://www.cnblogs.com/Enceladus/p/5011471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!