tjut 3511

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <set>
#include <algorithm>

using namespace std;

const int UP = 0;
const int DOWN = 1;
const int IN = 0;
const int OUT = 1;
const int N = 50005;

int Time;

struct circle {
    int x, y, r;
    int w;
    void read() {
        scanf("%d %d %d", &x, &y, &r);
        w = 0;
    }
    int getX(int flag) {
        if( flag == IN )     return x - r;
        else                return x + r;
    }
    double getY(int flag) {
        double ret = sqrt((double)r*r-(double)(Time-x)*(Time-x));
        if( flag == UP )     return (double)y + ret;
        else                return (double)y - ret;
    }
    
} cir[N];

struct event {
    int x, y, id;
    int flag;
    void get(int _x, int _y, int _id, int _flag) {
        x = _x;
        y = _y;
        id = _id;
        flag = _flag;
    }
    bool operator<(const event ev) const {
        return x < ev.x || x == ev.x && y > ev.y;
    }
} eve[N*2];

struct node {
    int id;
    int flag;
    node(){}
    node(int _id, int _flag) {
        id = _id;
        flag = _flag;
    }
    bool operator<(const node a) const {
        double y1 = cir[id].getY(flag);
        double y2 = cir[a.id].getY(a.flag);
        return y1 > y2 || y1 == y2 && flag < a.flag;
    }
};

int n, eveN;

set<node> line;
set<node>::iterator it, f, e, p;

inline int max(int a, int b) { return a > b ? a : b;}

void moveline() {
    line.clear();
    for(int i = 0; i < eveN; i ++) {
        Time = eve[i].x;
        if( eve[i].flag == OUT ) {
            line.erase(node(eve[i].id, UP));
            line.erase(node(eve[i].id, DOWN));
        } else {
            it = line.insert(node(eve[i].id, UP)).first;
            e = f = it;
            e ++;
            int id = it->id;
            if( it == line.begin() || e == line.end() ) {
                cir[id].w = 1;
            } else {
                f --;
                if( f->id == e->id ) {
                    cir[id].w = cir[f->id].w + 1;
                } else {
                    cir[id].w = max( cir[f->id].w, cir[e->id].w);
                }
            }
            line.insert(node(eve[i].id, DOWN));
        }
    }
}

int main() {
    while( scanf("%d", &n) != EOF ) {
        eveN = 0;        
        for(int i = 0; i < n; i ++) {
            cir[i].read();
            eve[eveN++].get(cir[i].getX(IN), cir[i].y, i, IN);
            eve[eveN++].get(cir[i].getX(OUT), cir[i].y, i, OUT);
            
        }
        sort(eve, eve + eveN);
        moveline();
        int ans = 0;
        for(int i = 0; i < n; i ++) {
            ans = max(ans, cir[i].w);
        }
        printf("%d\n", ans);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值