Topic Link: Click to open the link
The main topic: given the position of n buildings x and height y, Spider-Man from the first building to the last building to save people, to use the spider silk, every time to the same height, and in the process can not be rubbed to the ground, ask the least number of times to use the spider. (Enter in order of X)
Data is too scary, by the coordinate DP, directly enumerate the scope of the building can control, find the minimum number of times to reach the coordinates of the first. Note that it is possible to arrive at the last or the last building.
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std; Define LL __int64#define INF 0x3f3f3f3fstruct node{ ll x, y;} P[5100]; int dp[1000010]; int main () { int t, N, L, K, I, J; scanf ("%d", &t); while (t--) { scanf ("%d", &n); for (i = 0; i < n; i++) scanf ("%d%d", &p[i].x, &p[i].y); Memset (Dp,inf,sizeof (DP)); dp[p[0].x] = 0; for (i = 1; i < n; i++) { L = sqrt (p[i].y*p[i].y-(P[I].Y-P[0].Y) * (P[I].Y-P[0].Y)); for (j = max (p[0].x,p[i].x-l); J < p[i].x; J + +) { if (dp[j] = = INF) continue; k = min (p[n-1].x,2*p[i].x-j); Dp[k] = min (dp[k],dp[j]+1); } } if (dp[p[n-1].x] = = INF) dp[p[n-1].x] =-1; printf ("%d\n", dp[p[n-1].x]); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Poj1925--spiderman (DP)