B-Nana in Wonderland Series-long jump Queen

Source: Internet
Author: User

B-Nana in Wonderland Series-long jump Queen

Time Limit: 2000/1000ms (java/others) Memory Limit: 128000/64000kb (java/others) Submit Statusproblem Description

Nana thought the piano is very uninteresting, abandoned the piano, continue to walk, Front is a lake, Nana thought of the other side of the lake, but Nana looked for a long time did not find the small bridge and boat, Nana also found that they are not immortal, not like eight Immortals crossing. Just when Nana worried, Nana found some rocks above the lake! Nana Brainwave, found that can follow the stone to jump acridine, so keep jumping, perhaps can jump to the other side!

Nana to the location of all the stones to tell you, and then Nana can jump the farthest distance is also know ~ please smart you tell Nana, she can reach the other side smoothly?

In order to be able to express the position of each stone smoothly, assuming that Nana is on the x-axis, the lake on the other side of the bank is a straight line y=y0, the stones in the lake are ordered two-tuple <x,y>, we can assume that the lake is infinite width, two stone distance for the geometric distance, The distance between the stone and the shore is from the point to the straight line.

Input

Multiple sets of data, first a positive integer T (t<=20) representing the number of data groups

For each set of data is first three integers y0 (1<=y0<=1000), N (0<=n<=1000), D (0<=d<=1000), respectively, the location of the lake on the other shore, the number of stones, Nana once the furthest distance to jump.

Next is n rows, each line being two integers x, y (0<=|x|<=1000,0<y<y0)

Output

For each set of data, if Nana can reach another shore of the lake, first output "YES", and then output an integer, which means Nana at least how many times to jump to the other shore,

If Nana cannot reach another shore of the lake, first output "NO", and then output an integer that represents Nana's closest distance from the other shore of the lake. (Note case)

Sample Input
24 3 10 10 20 36 3 20 11 22 3
Sample Output
Yes4no3
Hint

Example one, from the opposite side of the 0,2 (0,3), x-axis (0,1), a total of 4 steps, Output 4

Sample two, from the x-axis (0,1)---(2,3), at this time the distance from the other side is 3, the maximum jump distance of 2, can not reach the other side, so output 3;

Test instructions: Cross-river problem, the starting point for the x-axis, enter three numbers, Y0,n,d, respectively, y=y0 endpoint coordinates, n is the number of stones, D for each step can walk the maximum distance, give you the coordinates of n stone, ask you can pass these stones to the other side of the river, if possible, the output need to walk the shortest steps, Otherwise the nearest distance from the river bank is output; The problem is that you can find a shortest path and record the farthest y-coordinate distance you can get. To find the shortest path is to use a wide search, layers of traversal, record the number of layers, with the queue to save the points can be reached, need to feature processing (the x-axis as a point) can be.

1#include <iostream>2#include <stdio.h>3#include <math.h>4#include <stdio.h>5#include <string.h>6#include <stdlib.h>7#include <utility>8#include <map>9#include <queue>Ten #defineMAX (x, y) (() > (y)? ( x):(y)) One #defineMIN (x, Y) ((×) < (y)? ( x):(y)) A #defineSET (ID) memset (id,0,sizeof (ID)) - using namespacestd; -typedefstruct Point the { -     intX; -     intY; -     intSign/*Mark whether the current number has been used*/ + }xy; -XY x_y[10086];/*Number of points*/ + intLen;/*The maximum value that Len can walk at each step*/ A intend_y;/*the coordinates of the End_y River.*/ at intN/*N is the number of stones*/ - intsign;/*Sign record is able to reach the other side of the river*/ - DoubleDistance (xy p1,xy p2)/*Distance Formula*/ - { -     DoubleX=p2. X-p1.x,y=p2. Y-P1. Y; -     returnsqrt (x*x+y*y); in } - intBFS () to { +queue<int> q;/*The reference in the queue is the subscript of the corresponding point*/ -     inttimes=0;/*Times records the current position of this point in the queue*/ the     inttimes=1;/*Times Record the position of the end of the team*/ *     intmax_y=x_y[0]. y=0; $     intstep[10086];/*The record is currently the first level of search*/Panax NotoginsengSET (Step);/*Initialize*/ -Q.push (0);/*put the x-axis into the queue first*/ thex_y[0].sign=1;/*tagged x-axis used*/ +step[times]=0;/*record the current number of search layers to 0*/ A      while(!q.empty ())/*queue is not empty, continue operation*/ the     { +         intNow=q.front ();/*gets the team head element, as the current point*/ -Q.pop ();/*out team head element*/ $         if(X_y[now]. y+len>=end_y) {sign=1;return 1;}/*If the first step is able to*/ $Max_y=max (Max_y,x_y[now]. Y);/*record the distance from the farthest y-coordinate that can be reached*/ -          for(intj=1; j<=n;j++)/*the number of points is counted from the beginning, x_y[0] is the X-axis*/ -         { the             if(x_y[j].sign==1)Continue;/*judge whether the point is in the queue or not.*/ -             if(now==0)/*when this is x-axis, special handling, set coordinates (x,0)*/Wuyi{X_y[now]. x=X_y[j]. X;} the             DoubleJude_len=distance (X_y[now],x_y[j]);/*Ask for distance*/ -             if(Jude_len<=len)/*two point distance is less than the maximum distance to go*/ Wu             { - Q.push (j); Aboutstep[times++]=step[times]+1;/*number of layers for qualifying points = number of currently searched layers +1*/ $                 if(X_y[j]. Y&GT;=END_Y)/*if the current position exceeds the end point*/ -{sign=1;returnstep[times-1];} -                 if(X_y[j]. Y+LEN&GT;=END_Y)/*if the current position plus one step can exceed the end point*/ -{sign=1;return(step[times-1]+1);} Ax_y[j].sign=1;/*Mark whether this point has entered the queue*/ +             } the         } -times++; $     } the     if(!Sign ) the     returnmax_y; the  the  - } in intMain () the { the     intT,x,y,run_len; About     intMin_step; the xy now_xy; the     DoubleJude_len; thescanf"%d",&T); +      while(t--) -     { thescanf"%d%d%d",&end_y,&n,&Len);Bayi         { thesign=0; x_y[0].sign=0; the              for(intI=1; i<=n;i++) -             { -scanf"%d%d", &x_y[i]. x,&X_y[i]. Y); thex_y[i].sign=0;/*Initialize tag to 0*/ the             } themin_step=BFS (); the             if(sign) -printf"yes\n%d\n", min_step); the             Else theprintf"no\n%d\n", end_y-min_step); the         }94     } the     return 0; the } the 98 /* About 2 - Ten 2101 1 4102 2 3103 2 2104 1 6 the 8 5106 7 6107 1 8108 9 2109 7 9 the 5 4111  the */
View Code

Reprint please attach the original blog: http://www.cnblogs.com/LWF5201314614/p/4424634.html.

B-Nana Sleepwalking Wonderland series-long jump Queen

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.