bzoj:1665: [Usaco2006 open]the climbing Wall Climbing

Source: Internet
Author: User

Description

One of the most popular attractions in the county fair is the climbing wall. Bessie wants to plan she 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 have F (1 <= F <= 10,000) Hoof-holds at unique x, y coordinates expressed in millimeters. 0,0 is at the ground level in the left side of the wall. Hoof-holds is separated by at least millimeters since no cow can maneuver them if they is spaced too close! Bessie knows there is at least one. 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 is 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's at least H-1000 millimeters above the ground, she can nimbly climb from th ere onto the platform atop the wall. Bessie can starT at any X location and have a Y location <= millimeters. Given the height of the wall and the locations of the Hoof-holds, determine the smallest number of Hoof-holds Bessie Shoul D use to reach the top.

Bessie participated in the climbing wall race, with a wall width of 30000, high H (1001 <= H <= 30,000). The Wall has an F (1 <= F <= 10,000) different settling point (x, y). (0,0) in the lower left corner of the ground. All the stops are at least 300 apart. Bessie knew there was at least one way to go up. Bessie can only climb from one foothold to another with a distance of not more than 1000, she can crawl up and down in four directions. Similarly, once she reached a height of at least H-1000, she could climb to the top of the wall with agility. Bessie can start at any height of no more than 1000. Ask Bessie how many times to climb at least. The distance between these two points is Euclidean distance.

Input

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

* Lines 2..f+1:each Line contains-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's the smallest number of hoof-holds Bessie must use to reach the top of the climbing wall .

Sample Input3000 5
600 800
1600 1800
100 1300
300 2100
1600 2300

INPUT DETAILS:

The wall is three meters and 5 hoof-holds.
Sample Output3
Direct violence on ...
#include <queue>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;structna{intx, y;};structma{intx,y,q;};intn,m,x,l[30001],r[30001],dis[10001],j;na b[10001];CharC;queue<ma>Q;BOOLcmp (na a,na b) {if(a.x==b.x)returna.y<b.y; returna.x<b.x;}BOOLAble (MA A,na b) {intlx=a.x-b.x,ly=a.y-b.y; if(lx*lx+ly*ly<=1000000)return 1;Else return 0;}intRead () {x=0; c=GetChar ();  while(c<'0'|| C>'9') c=GetChar ();  while(c>='0'&&c<='9') x=x*Ten+c- -, c=GetChar (); returnx;}intMain () {n=read (); m=read ();  for(intI=1; i<=m;i++) {b[i].x=read (), b[i].y=read (); if(b[i].y<= +) {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(intI=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(intI=0; i<=30000; i++)if(r[i]==0) r[i]=r[i-1];  for(intI=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+ +, N)];  for(intI=l[max (k.x- +,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- +) {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&GT;=K.Y) i=l[b[i].x+1]-1; }    }}

bzoj:1665: [Usaco2006 open]the climbing Wall Climbing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.