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);
    }
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luozhong11/article/details/52366139
上一篇tjut 3516
下一篇tjut 3508
想对作者说点什么? 我来说一句

海思3511 3512开发板PCB

2010年09月09日 1.81MB 下载

华为海思HI3511硬件参考原理图PCB

2015年09月16日 3.97MB 下载

没有更多推荐了,返回首页

关闭
关闭