Test instructions: BFS
Problem-solving ideas: To build a BFS, to be a special judge can jump directly.
Problem Solving Ideas:
1 //File name:b.cpp2 //Author:darkdream3 //Created time:2015 April 12 Sunday 20:03 02 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <queue> -#include <ctime> - #defineLL Long Long - - using namespacestd; - intT; invector<int>mp[10005]; - intN; to intD,yd; + intDisDoubleX1,DoubleY1,DoubleX2,Doubley2) - { the DoubleAns = sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (y1-y2)); * if(Ans <=d) $ return 1; Panax Notoginseng return 0 ; - } the structnode{ + intx, y; A}p[10005]; the intvis[10005]; + intOK; - structqunode{ $ intnum, step; $ Qunode () {} -Qunode (int_num,int_step) - { thenum =_num; -Step =_step;Wuyi } the }; - intBFS () Wu { -OK =0 ; AboutQueue<qunode>Qu; $Qu.push (Qunode (0,0)); - intMians =yd; - /*for (int i = 1;i <= n;i + +) - { A For (int j = 0; J<mp[i].size (); j + +) + printf ("%d", mp[i][j]); the printf ("******\n"); - }*/ $ while(!qu.empty ()) the { theQunode tmp =Qu.front (); the //printf ("%d\n", tmp.num); the Qu.pop (); -Mians = min (mians,yd-p[tmp.num].y); in the if(Tmp.num = = n+1) the { AboutOK =1; the returnTmp.step; the } the for(inti =0; i < mp[tmp.num].size (); i + +) + { - if(!Vis[mp[tmp.num][i]]) the {Bayi //printf ("%d to%d\n", Tmp.num,mp[tmp.num][i]); theVis[mp[tmp.num][i]] =1; theQu.push (Qunode (mp[tmp.num][i],tmp.step+1)); - } - } the the } the returnMians; the } - intMain () { thescanf"%d",&t); the while(t--){ theOK =0 ; 94memset (Vis,0,sizeof(Vis)); the for(inti =0; I <=10000; i + +) the mp[i].clear (); the 98scanf" %d%d%d",&yd,&n,&d); About for(inti =1; I <= N;i + +) - {101scanf"%d%d",&p[i].x,&p[i].y);102 }103 if(Yd <=d)104mp[0].push_back (n+1); the for(inti =1; I <= N;i + + )106 {107 if(P[i].y <=d)108 {109mp[0].push_back (i); the }111 if(Yd-p[i].y <=d) the {113Mp[i].push_back (n+1); the } the for(intj = i+1; J <= N;j + +) the {117 if(DIS (p[i].x,p[i].y,p[j].x,p[j].y))118 {119 Mp[i].push_back (j); - Mp[j].push_back (i);121 }122 }123 }124 inttt =BFS (); the if(OK)126printf"yes\n%d\n", TT);127 Elseprintf"no\n%d\n", TT); - }129 return 0; the}
View Code
Acdream Hut Freshman Training tournament B-Nana Sleepwalking Wonderland series-long jump Queen BFs