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;
}
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(){
for (int i=1;i<=m;i++){
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;
}
}
}```
• 相关阅读:
Sql 三元运算符
连表更新
SQL分组排序去重复
ASP日常出错原因
Box2D的三种Body类型
Android获取屏幕尺寸的方法
AndEngine之ScreenCapture
AndEngine之IUpdateHandler,IEntityModifier
JAVA中线程安全的类
AndEngine引擎之SmoothCamera 平滑摄像机