POJ 1925 Spiderman(DP)

题目链接

这个破题,好不容易思路清楚了,写的就是过不了。。关键部分直接抄的别人的。。。终于A了,自己写的判断什么的,就是有一组数据过不了。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 #define INF 0x3f3f3f3f
 8 #define LL __int64
 9 int dp[3000010];
10 struct node
11 {
12     int x,y;
13 } p[5001];
14 #define eps 1e-6
15 int main()
16 {
17     int t,i,j,n,ans;
18     scanf("%d",&t);
19     while(t--)
20     {
21         scanf("%d",&n);
22         for(i = 0; i < n; i ++)
23         {
24             scanf("%d%d",&p[i].x,&p[i].y);
25         }
26         for(i = 0; i < 3000000; i ++)
27             dp[i] = INF;
28         dp[p[0].x] = 0;
29         ans = INF;
30         for(i = 1; i < n; i ++)
31         {
32             for(j = p[i].x;; j ++)
33             {
34                 LL dx = j-p[i].x, dy = p[i].y-p[0].y;
35                 if( dx*dx+dy*dy > 1LL*p[i].y*p[i].y ) break;
36                 if( 2*p[i].x-j >= p[0].x )
37                     dp[j] = min(dp[j], dp[2*p[i].x-j]+1);
38                 else
39                 break;
40                 if( j >= p[n-1].x && dp[j] < ans )
41                 {
42                     ans = dp[j];
43                 }
44             }
45         }
46         if(ans >= INF)
47             printf("-1
");
48         else
49             printf("%d
",ans);
50     }
51     return 0;
52 }
原文地址:https://www.cnblogs.com/naix-x/p/3184966.html