| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
泪流满面啊,当年课上遇到这题的时候还感觉挺难,得照着讲义上的代码抄才能过。现在一会就1Y了,感慨一下继续努力,内有代码攒rp#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAXN 1111
#define INF 1000000000
#define LT 0
#define RT 1
struct board {
int x[2];
int y;
} b[MAXN];
int dp[MAXN][2];
int mx, n;
int
calc(int num, int lr) {
if(b[num].y == 0)
return 0;
if(dp[num][lr])
return dp[num][lr];
int i = num + 1;
int ll, rl;
for(; i < n + 2; i++) {
if(b[i].y >= b[num].y)
continue;
ll = b[num].x[lr] - b[i].x[0];
rl = b[i].x[1] - b[num].x[lr];
if(ll >= 0 && rl >= 0)
break;
}
dp[num][lr] = b[num].y - b[i].y;
if(dp[num][lr] > mx)
return (dp[num][lr] = INF);
if(i == n + 1)
return dp[num][lr];
dp[num][lr] += min(ll + calc(i, LT), rl + calc(i, RT));
return dp[num][lr];
}
int
cmp(const void *p, const void *q) {
return (*(struct board *)q).y - (*(struct board *)p).y;
}
int
main() {
int t;
scanf("%d\n", &t);
while(t--) {
int x, y;
memset(dp, 0, sizeof(int)*2*MAXN);
scanf("%d %d %d %d", &n, &x, &y, &mx);
b[n].x[0] = b[n].x[1] = x;
b[n].y = y;
b[n + 1].x[0] = -22222;
b[n + 1].x[1] = 22222;
b[n + 1].y = 0;
for(int i = 0; i < n; i++)
scanf("%d %d %d", &b[i].x[0], &b[i].x[1], &b[i].y);
qsort(b, n + 2, sizeof(struct board), cmp);
printf("%d\n", calc(0, LT));
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator