hdu5714 百度之星复赛C

恩。。大概就是如果 y - z <= x +z , 那么 对于这一艘船来说,在[y - z , x +z ]这个区域都可以完整的观察到它

转换成 y - z 为左端点,x + z 为右端点,的n 条线段

把向右走的船看成固定不动的, 在这些船右边, 向左走的船在同一时刻最多有多少条

now记录当前端点处,垂直河岸的线能交叉几条(向左,向右)线段,ans[i]记录当前端点右侧,垂直河岸的线最多能交叉几条(向左)线段

sort的时候,先按位置从小到大排,再按左端点右端点排,最后按向左或向右排都无所谓啦

#include <iostream>
#include<stdio.h>
#include<cctype>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define mod 1000000007
#define FOR(i,j,k) for(int i=j;i<=k;i++)
const int inf=0x3f3f3f3f;
const int maxn = 20010;
struct node
{
    int x, val , op;
    friend bool operator <(const node &a, const node &b)
    {
        if (a.x != b.x) return a.x < b.x;
        if (a. val  != b.val) return a.val > b.val;
        return a.op < b.op;
    }
    
}nd[maxn];
int ans[maxn];
int main()
{
    int T;
    scanf("%d" , &T);
    FOR(z, 1, T)
    {
        int n;
        scanf("%d" ,&n);
        int tot = 0;
        FOR(i, 1, n)
        {
            int x,y,z, op;
            scanf("%d%d%d%d" , & x, &y, &z, & op);
            if(y - z <= x +z){
                tot++;
                nd[tot].x= y-z, nd[tot].val = 1, nd[tot].op = op;
                tot++;
                nd[tot].x= x+z, nd[tot].val = -1, nd[tot].op = op;

            }
        }
        sort(nd +1, nd+1 +tot);
    
        memset(ans , 0,sizeof(ans));
        int now =0;
        
        for(int i = tot; i>= 1;i--)
        {
            if(nd[i].op == -1 && nd[i].val == -1) now ++;
            ans[i] = max(ans[i+1] , now);
            if(nd[i].op == -1 && nd[i].val == 1) now--;
        }
        
        now = 0;
        int sum = 0;
        FOR(i, 1, tot)
        {
            if(nd[i]. op == 1)
            {
                if(nd[i].val == 1 ) now ++;
                sum = max(sum, now + ans[i]);
                if(nd[i].val == -1) now --;
            }
        }
        printf("Case #%d:\n%d\n",z,sum);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值