HDU Ball

Ball

Time Limit : 60000/20000ms (Java/Other)   Memory Limit : 62768/62768K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

Members of Wuhan University ACM Team are fond of playing little games. Ball game is one of them, which is 
played with a ball on a rectangle board. The ball should be rolled from the start point to the end point. The 
game board is surrounded by walls and contains rectangular obstacles with known dimensions. Obstacles will 
not overlap with each other. The ball cannot leave the board, nor can it fly. 

Now, you're one of the competitors. Can you find the radius of the largest ball to complete the task?

Input

The input consists of multiple test cases. The first line of input contains an integer T, which is the number of 
test cases.Each test case is on several lines. The first line contains four integers: N, L, W, H, indicating the 
number of obstacles; the length, width of the board; and the height of walls. 

The coordinate of the lower-left corner is (0,0), the upper-right one is (L, W). 

Each of the following N lines consists of five integers: Xi, Yi, Li, Wi, Hi, indicating the coordinate of the 
lower-left corner of an obstracle and it's length, width and height. So the upper-right corner of the obstracle 
is (Xi + Li, Yi + Wi). 

The last line of a test case consists of four integers: Sx, Sy, Tx, Ty which indicate the coordinates of 
start point:(Sx, Sy), and end point:(Tx, Ty). 

[Technical Specification] 
T is an integer, and T <= 50. 
N is an integer, and 0 <= N <=10. 
All integers EXCEPT N are in the range [1, 1000]. 
You can assume those obstracles? sides are parallel to OX, OY and OZ axis, the start point and end point are 
rightful(not outside the board or inside an obstracle). 
All part of an obstracle is in the board. 
The integers on the same line are separated by ONE space. 
The test cases are separated by ONE empty line. 
NO other spaces or lines will appear in the test data.

Output

For each test case, print a single line consists of the radius of the largest ball, rounded to two fractional 
digits. Output '0.00'(without quotes) if there is no ball can reach its end point from the start point.

Sample Input

4 
3 1000 1000 42 
102 101 3 2 468 
106 104 2 3 335 
100 107 4 1 501 
101 106 106 100 

4 1000 1000 170 
108 103 2 3 725 
105 109 4 1 479 
101 104 1 4 359 
103 101 2 2 963 
100 100 105 106 

2 1000 1000 465 
102 100 2 3 706 
106 103 2 3 146 
100 103 110 103 

0 1000 1000 282 
100 100 102 102 

Sample Output

1.00 
1.58 
2.00 
100.00 

Source

The 4th Baidu Cup Central China Invitational Programming Contest



#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define rep(i,j,k)for(i=j;i<k;i++)
#define per(i,j,k)for(i=j;i>k;i--)
#define MS(x,y)memset(x,y,sizeof(x))
#define clr(x)memset(x,0,sizeof(x))
typedef long long LL;
const int INF =0x7FFFFFFF;
const int low(int x){return x&-x;}

int min(int a,int b)
{
    return a<b?a:b;
}

int ab(int x)
{
    return x>0?x:-x;
}

struct node
{
    int pos, w;
}b[60][1005];
int dp[60][1005];
int q[1005];

bool cmp(node a,node b)
{
    return a.pos<b.pos;
}

int main()
{
    int i, j, k;
    int t, x, n, m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d %d",&n, &m, &x);
        for(i = 0; i < n; i++)
            for(j = 0; j < m; j++)
                scanf("%d",&b[i][j].pos);
        for(i = 0; i < n; i++){
            for(j = 0; j < m; j++)
                scanf("%d",&b[i][j].w);
            sort(b[i],b[i]+m,cmp);
        }
        for(i = 0; i < m; i++)
            dp[0][i] = ab(x-b[0][i].pos)+b[0][i].w;
        int dmin;
        for(i = 1; i < n; i++){
            k = 0;
            dmin = INF;
            for(j = 0; j < m; j++){
                while(k < m && b[i][j].pos >= b[i-1][k].pos){
                    dmin = min(dp[i-1][k]-b[i-1][k].pos,dmin);
                    k++;
                }
                dp[i][j] = dmin + b[i][j].pos + b[i][j].w;
            }
            k = m-1;
            dmin = INF;
            for(j = m-1; j >= 0; j--){
                while(k >= 0 && b[i][j].pos <= b[i-1][k].pos){
                    dmin = min(dp[i-1][k]+b[i-1][k].pos,dmin);
                    k--;
                }
                dp[i][j] = min(dp[i][j],dmin-b[i][j].pos+b[i][j].w);
            }
        }
        dmin = dp[n-1][0];
        for(i = 1; i < m; i++)
            dmin = min(dmin,dp[n-1][i]);
        printf("%d\n",dmin);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值