标签:问题 不能 ota turn limit stream 分享 重叠 desc
题目链接:http://poj.org/problem?id=1661
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 12537 | Accepted: 4160 |
Description
Input
Output
Sample Input
1 3 8 17 20 0 10 8 0 10 13 4 14 3
Sample Output
23
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 #define ms(a,b) memset((a),(b),sizeof((a))) 13 using namespace std; 14 typedef long long LL; 15 const double EPS = 1e-8; 16 const int INF = 2e9; 17 const LL LNF = 2e18; 18 const int MAXN = 1e3+10; 19 20 struct node 21 { 22 int l, r, h; 23 bool operator<(const node &x) const{ 24 return h>x.h; 25 } 26 }a[MAXN]; 27 int dp[MAXN][2]; 28 29 int main() 30 { 31 int T, n, x, y, mh; 32 scanf("%d", &T); 33 while(T--) 34 { 35 scanf("%d%d%d%d", &n,&x,&y,&mh); 36 for(int i = 1; i<=n; i++) 37 scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].h); 38 a[++n].l = a[n].r = x; a[n].h = y; 39 40 sort(a+1, a+1+n); 41 for(int i = 1; i<=n; i++) 42 dp[i][0] = dp[i][1] = INF; 43 44 int ans = INF; 45 dp[1][0] = dp[1][1] = 0; 46 for(int i = 1; i<=n; i++) 47 { 48 if(dp[i][0]==INF) continue; 49 bool left = false, right = false; 50 for(int j = i+1; j<=n; j++) 51 { 52 int dis_h = a[i].h - a[j].h; 53 if(dis_h>mh) break; 54 if(!left && a[j].l<=a[i].l && a[i].l<=a[j].r ) 55 { 56 left = true; 57 dp[j][0] = min(dp[j][0], dp[i][0] + dis_h + a[i].l-a[j].l); 58 dp[j][1] = min(dp[j][1], dp[i][0] + dis_h + a[j].r-a[i].l); 59 } 60 if(!right && a[j].l<=a[i].r && a[i].r<=a[j].r ) 61 { 62 right = true; 63 dp[j][0] = min(dp[j][0], dp[i][1] + dis_h + a[i].r-a[j].l); 64 dp[j][1] = min(dp[j][1], dp[i][1] + dis_h + a[j].r-a[i].r); 65 } 66 67 if(left && right) break; 68 } 69 70 if(a[i].h<=mh) 71 { 72 if(!left) ans = min(ans, dp[i][0]+a[i].h); 73 if(!right) ans = min(ans, dp[i][1]+a[i].h); 74 } 75 } 76 77 printf("%d\n", ans); 78 } 79 }
标签:问题 不能 ota turn limit stream 分享 重叠 desc
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7631242.html