| ||||||||||
| 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 | |||||||||
温馨提示:从一个板子到另一个板子的时候,中间的板子不能直接穿过!!AC代码:
```cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1005;
const int INF = 0x3f3f3f3f;
struct p
{
//左右端点,高度
int l, r, h;
bool operator<(const p& rhs)const
{
if (h != rhs.h)
return h > rhs.h;
else
return l < rhs.l;
}
}p[N];
int f[N][2];
int main()
{
int t;
cin >> t;
while (t--)
{
memset(f, 0x3f, sizeof f);
int n, x, y, MAX;
cin >> n >> x >> y >> MAX;
p[0].l = x, p[0].r = x, p[0].h = y;
for (int i = 1; i <= n; ++i)
cin >> p[i].l >> p[i].r >> p[i].h;
//平台高度从大到小排序
sort(p + 1, p + n + 1);
f[0][0] = f[0][1] = 0;
//从前面的板子到达k号板子左右端的最短时间
for (int k = 1; k <= n; ++k)
{
for (int i = 0; i < k; ++i)
{
if (MAX >= p[i].h - p[k].h)
{
for (int j = i + 1; j <= k - 1; ++j)
{
if (p[i].l >= p[j].l && p[i].l <= p[j].r)
goto here1;
}
if (p[i].l >= p[k].l && p[i].l <= p[k].r)
{
f[k][0] = min(f[k][0], f[i][0] + p[i].h - p[k].h + p[i].l - p[k].l);
f[k][1] = min(f[k][1], f[i][0] + p[i].h - p[k].h + p[k].r - p[i].l);
}
here1:;
for (int j = i + 1; j <= k - 1; ++j)
{
if (p[i].r >= p[j].l && p[i].r <= p[j].r)
goto here2;
}
if (p[i].r >= p[k].l && p[i].r <= p[k].r)
{
f[k][0] = min(f[k][0], f[i][1] + p[i].h - p[k].h + p[i].r - p[k].l);
f[k][1] = min(f[k][1], f[i][1] + p[i].h - p[k].h + p[k].r - p[i].r);
}
here2:;
}
}
}
int res = INF;
//达到地面
for (int i = 0; i <= n; ++i)
{
bool flag1 = false, flag2 = false;
for (int j = i + 1; j <= n; ++j)
{
if (!(p[i].l < p[j].l || p[i].l > p[i].r))
flag1 = true;
if (!(p[i].r < p[j].l || p[i].r > p[j].r))
flag2 = true;
}
if (!flag1 && p[i].h <= MAX)
res = min(res, f[i][0] + p[i].h);
if (!flag2 && p[i].h <= MAX)
res = min(res, f[i][1] + p[i].h);
}
cout << res << endl;
}
return 0;
}
```
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator