POJ 2932 Coneology(扫描线)

题意:

$N\le 4\times 10^4个圆,所有圆不相交和相切,输出所有最外层的圆$

分析:

$显然n^2枚举标记内层圆是不可以的,虽然有很多剪枝$
$这种题就考虑扫描线了,把每个圆拆成进入事件和出去的事件$
$考虑用set维护一下外层圆的y坐标$
$显然最有可能包含是离它最近的,判一判就好了,而且有且只有他一个$
$反证一下就好了,如果远的包含,那么上面这个之前就没有被丢进来$
$时间复杂度O(nlogn)$

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Created by TaoSama on 2016-08-22
// Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n;
double x[N], y[N], r[N];
bool isInside(int i, int j) {
double dx = x[i] - x[j], dy = y[i] - y[j];
return dx * dx + dy * dy <= r[j] * r[j];
}
int main() {
#ifdef LOCAL
freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
while(scanf("%d", &n) == 1) {
vector<pair<double, int> > events;
for(int i = 1; i <= n; ++i) {
scanf("%lf%lf%lf", r + i, x + i, y + i);
events.push_back(make_pair(x[i] - r[i], i));
events.push_back(make_pair(x[i] + r[i], -i));
}
sort(events.begin(), events.end());
vector<int> ans;
set<pair<double, int> > outers;
for(int i = 0; i < events.size(); ++i) {
int id = events[i].second;
if(id > 0) {
set<pair<double, int> >::iterator iter =
outers.lower_bound(make_pair(y[id], -1));
if(iter != outers.end() && isInside(id, iter->second)) continue;
if(iter != outers.begin() && isInside(id, (--iter)->second)) continue;
ans.push_back(id);
outers.insert(make_pair(y[id], id));
} else outers.erase(make_pair(y[-id], -id));
}
sort(ans.begin(), ans.end());
printf("%d\n", ans.size());
for(int i = 0; i < ans.size(); ++i) {
printf("%d%c", ans[i], " \n"[i == ans.size() - 1]);
}
}
return 0;
}

1. 除非注明,本博文即为原创,转载请注明链接地址
2. 本博文只代表博主当时的观点或结论,请不要恶意攻击
3. 如果本文帮到了您,不妨点一下 下面分享到 按钮,让更多的人看到