Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

被WA逼疯了o(>﹏<)o

Posted by Onlynagesha at 2017-12-01 22:03:00 on Problem 2932
不会真的测试数据有问题吧……

附代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

const int maxN = 4e4 + 5;

struct Circle
{
    double x, y, r;

    Circle(double _x = 0, double _y = 0, double _r = 0): x(_x), y(_y), r(_r) {}

    void assign(double _x, double _y, double _r)
    {
        this->x = _x;
        this->y = _y;
        this->r = _r;
    }

    bool operator < (const Circle& rhs) const
    {
        return y < rhs.y || (y == rhs.y && x < rhs.x);
    }
};

struct Event
{
    static const int circleIn = 0;
    static const int circleOut = 1;

    int circleId;
    int event;
    double pos;

    Event(int id, int e, double p): circleId(id), event(e), pos(p) {}

    bool operator < (const Event& rhs) const
    {
        return (pos < rhs.pos) || (pos == rhs.pos && circleId < rhs.circleId);
    }
};

bool cmpX(const Circle& lhs, const Circle& rhs)
{
    return lhs.x < rhs.x || (lhs.x == rhs.x && lhs.y < rhs.y);
}

inline bool isCovered(const Circle& inner, const Circle& outer)
{
    double dx = inner.x - outer.x;
    double dy = inner.y - outer.y;
    double dr = inner.r - outer.r;
    return dx * dx + dy * dy <= dr * dr;
}

int N;
Circle circle[maxN];

void input()
{
    double x, y, r;

    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lf%lf%lf", &r, &x, &y);
        //circle[i].assign(x, y, r);
        circle[i].assign(y, x, r);
    }
}

void initEvent(vector<Event>& vec)
{
    for (int i = 0; i < N; i++)
    {
        vec.push_back(Event(i, Event::circleIn, circle[i].x - circle[i].r));
        vec.push_back(Event(i, Event::circleOut, circle[i].x + circle[i].r));
    }
    sort(vec.begin(), vec.end());
}

void solve()
{
    vector<Event> eventVec;
    set<Circle> scanSet;
    set<int> ansSet;

    initEvent(eventVec);
    for (vector<Event>::iterator it = eventVec.begin(); it != eventVec.end(); ++it)
    {
        if (it->event == Event::circleOut)
        {
            set<Circle>::iterator pos = scanSet.find(circle[it->circleId]);
            if (pos != scanSet.end())
            {
                ansSet.insert(it->circleId);
                scanSet.erase(pos);
            }
        }
        else
        {
            set<Circle>::iterator pos = scanSet.lower_bound(Circle(0, circle[it->circleId].y, 0));
            if (pos != scanSet.end() && isCovered(circle[it->circleId], *pos))
                continue;
            if (pos != scanSet.begin() && isCovered(circle[it->circleId], *(--pos)))
                continue;
            scanSet.insert(circle[it->circleId]);
        }
    }

    printf("%d\n", (int)ansSet.size());
    for (set<int>::iterator it = ansSet.begin(); it != ansSet.end(); ++it)
        printf("%d ", 1 + *it);
}

int main()
{
    input();
    solve();
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator