关闭

tjut 3511

45人阅读 评论(0) 收藏 举报
分类:
#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);
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:30819次
    • 积分:4433
    • 等级:
    • 排名:第6954名
    • 原创:433篇
    • 转载:0篇
    • 译文:0篇
    • 评论:11条
    文章分类