B-Nana in Wonderland Series-long jump QueenTime Limit:2000/1000ms (java/others) Memory Limit: 128000/64000kb (java/others) Problem 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
Example two, from the x-axis (0,1)---(2,3), at this time the distance from the other shore is 3, the maximum jump distance of 2, can not reach the other side, so output 3
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <stack>9#include <queue>Ten#include <Set> One#include <map> A#include <list> -#include <iomanip> -#include <cstdlib> the#include <sstream> - using namespacestd; -typedefLong LongLL; - Const intinf=0x5fffffff; + Const Doubleexp=1e-6; - Const intms=1005; + A intDES,N,MAXV; at - - DoubleEdges[ms][ms]; - intCnt[ms]; - BOOLFlag[ms]; - in - struct Point to { + intx, y; - }points[ms]; the * DoubleDistence (Point &a,point &b) $ {Panax Notoginseng returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); - } the + intMain () A { the intT; +scanf"%d",&T); - while(t--) $ { $scanf"%d%d%d",&des,&n,&MAXV); - intx, y; - for(intI=1; i<=n;i++) the { -scanf"%d%d",&x,&y);Wuyipoints[i].x=x; thepoints[i].y=y; - } Wu - for(intI=1; i<=n;i++) Aboutcnt[i]=INF; $ -memset (Flag,false,sizeof(flag)); - -queue<int>que; A + for(intI=1; i<=n;i++) the { - if(points[i].y<=MAXV) $ { thecnt[i]=1; the Que.push (i); the } the if(des-points[i].y<=MAXV) -flag[i]=true; in for(intj=i+1; j<=n;j++) the { theedges[i][j]=edges[j][i]=distence (Points[i],points[j]); About } the } the while(!que.empty ()) the { + intu=Que.front (); - Que.pop (); the for(intv=1; v<=n;v++)Bayi { the if((u!=v) &&edges[u][v]<= (Double) (maxv+EXP)) the { - if(cnt[u]+1<Cnt[v]) - { thecnt[v]=cnt[u]+1; the Que.push (v); the } the } - } the the } the 94 if(des<=MAXV) the { theprintf"yes\n1\n"); the Continue;98 } About - if(n==0)101 {102 if(des<=MAXV)103printf"yes\n1\n");104 Else theprintf"no\n%d\n", des);106 Continue;107 }108 109 intcn1=INF; the intt=0;111 for(intI=1; i<=n;i++) the {113 if(Flag[i]) the { the if(cnt[i]<INF) the {117 if(ans>cnt[i]+1)118ans=cnt[i]+1;119 } - }121 if(cnt[i]<INF)122 {123 if(points[i].y>t)124t=points[i].y; the }126 }127 - if(ans<INF)129 { theprintf"yes\n");131printf"%d\n", ans); the }133 Else134 {135printf"no\n");136printf"%d\n", des-t);137 }138 }139 return 0; $}
B-Nana in Wonderland Series-long jump Queen