Test instructions: In a two-dimensional plane, the speed of a person walking is 5m/s, there are n cannons in the plane, the range is fixed to 50m and the time is 2 seconds, ask you the shortest time.
Problem-solving ideas: the shortest circuit
Problem Solving Code:
1 //File name:e.cpp2 //Author:darkdream3 //Created time:2015 March 14 Saturday 16:47 54 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 <ctime> - #defineLL Long Long - - using namespacestd; - Doublemp[ $][ $]; - structnode{ in Doublex, y; -}dapao[ $],be,en; to intN; + DoubleDisDoubleX1,DoubleX2,DoubleY1,Doubley2) - { the returnsqrt ((x1-y1) * (x1-y1) + (x2-y2) * (x2-y2)); * } $ Doublemi;Panax Notoginseng intMain () { -scanf"%LF%LF",&be.x,&be.y); thescanf"%LF%LF",&en.x,&en.y); + Ami = Dis (BE.X,BE.Y,EN.X,EN.Y)/5; thescanf"%d",&n); + -dapao[n+1].x =en.x; $dapao[n+1].Y =EN.Y; $ for(inti =1; I <= N;i + +) - { -scanf"%LF%LF",&dapao[i].x,&dapao[i].y); the } - for(intI=1; I <= N;i + +)Wuyi { the for(intj =1; J <= n+1; J + +) - { Wu Doubletmp; -MP[I][J] =dis (dapao[i].x,dapao[i].y,dapao[j].x,dapao[j].y); AboutTMP =2+ Fabs (50.0-MP[I][J])/5 ; $Mp[i][j] = min (mp[i][j]/5, TMP); - } - } - for(intk=1; k <= N;k + +) A { + for(inti =1; I <= N;i + +) the { - for(intj =1; J <= N +1; j + +) $Mp[i][j] = min (Mp[i][j],mp[i][k] +mp[k][j]); the } the } the for(inti =1; I <= N;i + +) the { -mi = min (Mi,dis (BE.X,BE.Y,DAPAO[I].X,DAPAO[I].Y)/5+mp[i][n+1]); in } theprintf"%f\n", MI); the return 0; About}View Code
ACM-ICPC North America Qualifier Human Cannonball Run