poj2932 Coneology (扫描线)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Coneology

Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 3289   Accepted: 586

Description

A student named Round Square loved to play with cones. He would arrange cones with different base radii arbitrarily on the floor and would admire the intrinsic beauty of the arrangement. The student even began theorizing about how some cones dominateother cones: a cone A dominates another cone B when cone B is completely within the cone A. Furthermore, he noted that there are some cones that not only dominate others, but are themselves dominated, thus creating complex domination relations. After studying the intricate relations of the cones in more depth, the student reached an important conclusion: there exist some cones, all-powerful cones, that have unique properties: an all-powerful cone is not dominated by any other cone. The student became so impressed by the mightiness of the all-powerful cones that he decided to worship these all-powerful cones.

Unfortunately, after having arranged a huge number of cones and having worked hard on developing this grandiose cone theory, the student become quite confused with all these cones, and he now fears that he might worship the wrong cones (what if there is an evil cone that tries to trick the student into worshiping it?). You need to help this student by finding the cones he should worship.

Input

The input le specifies an arrangement of the cones. There are in total N cones (1 ≤ N ≤ 40000). Cone i has radius and height equal to Rii = 1 … N. Each cone is hollow on the inside and has no base, so it can be placed over another cone with smaller radius. No two cones touch.

The first line of the input contains the integer N. The next N lines each contain three real numbers Rixiyi separated by spaces, where (xiyi) are the coordinates of the center of the base of cone i.

Output

The first line of the output le should contain the number of cones that the student should worship. The second line contains the indices of the cones that the student should worship in increasing order. Two consecutive numbers should be separated by a single space.

Sample Input

5
1 0 -2
3 0 3
10 0 0
1 0 1.5
10 50 50

Sample Output

2
3 5

这题并不难,和多校的某道题稍微思想上有点像。

问不包含于其他圆内部的圆的数目。

取所有的左端点和右端点,排序后一次取,对于在内部的圆,其外部的圆一定只取到了左端点,那么我们对于当前只取到左端点的圆,只需要判断这个圆的纵坐标是否在那些只取到左端点的圆的纵坐标之间。因为不会相交,所以可以这样搞。

 1 /**
 2  * code generated by JHelper
 3  * More info: https://github.com/AlexeyDmitriev/JHelper
 4  * @author xyiyy @https://github.com/xyiyy
 5  */
 6
 7 #include <iostream>
 8 #include <fstream>
 9
10 //#####################
11 //Author:fraud
12 //Blog: http://www.cnblogs.com/fraud/
13 //#####################
14 //#pragma comment(linker, "/STACK:102400000,102400000")
15 #include <iostream>
16 #include <sstream>
17 #include <ios>
18 #include <iomanip>
19 #include <functional>
20 #include <algorithm>
21 #include <vector>
22 #include <string>
23 #include <list>
24 #include <queue>
25 #include <deque>
26 #include <stack>
27 #include <set>
28 #include <map>
29 #include <cstdio>
30 #include <cstdlib>
31 #include <cmath>
32 #include <cstring>
33 #include <climits>
34 #include <cctype>
35
36 using namespace std;
37 #define mp(X, Y) make_pair(X,Y)
38 #define pb(X) push_back(X)
39 #define rep(X, N) for(int X=0;X<N;X++)
40 #define IT iterator
41 #define ALL(X) (X).begin(),(X).end()
42
43 double r[40010], x[40010], y[40010];
44 vector<pair<double, int> > vec;
45 set<pair<double, int> > s;
46 bool mark[40010];
47 vector<int> ans;
48
49 bool contain(int a, int b) {
50     return ((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]) <= r[b] * r[b]);
51 }
52
53 class poj2932 {
54 public:
55     void solve(std::istream &in, std::ostream &out) {
56         int n;
57         while (in >> n) {
58             vec.clear();
59             s.clear();
60             ans.clear();
61             rep(i, n)in >> r[i] >> x[i] >> y[i];
62             rep(i, n) {
63                 vec.pb(mp(x[i] - r[i], i));
64                 vec.pb(mp(x[i] + r[i], i + n));
65             }
66             sort(ALL(vec));
67             int num = 0;
68             rep(i, vec.size()) {
69                 int j = vec[i].second;
70                 if (j < n) {
71                     set<pair<double, int> >::IT it = s.lower_bound(mp(y[j], j));
72                     if (it != s.end() && contain(j, it->second))continue;
73                     if (it != s.begin() && contain(j, (--it)->second))continue;
74                     s.insert(mp(y[j], j));
75                     mark[j + 1] = 1;
76                     num++;
77                 } else {
78                     s.erase(mp(y[j - n], j - n));
79                 }
80             }
81             out << num << endl;
82             rep(i, n) {
83                 if (mark[i + 1])out << i + 1 << " ";
84             }
85             out << endl;
86         }
87     }
88 };
89
90 int main() {
91     std::ios::sync_with_stdio(false);
92     std::cin.tie(0);
93     poj2932 solver;
94     std::istream &in(std::cin);
95     std::ostream &out(std::cout);
96     solver.solve(in, out);
97     return 0;
98 }

代码君

时间: 2024-08-25 23:43:02

poj2932 Coneology (扫描线)的相关文章

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

刷题总结——coneology(poj2932 扫描线)

题目: Description A student named Round Square loved to play with cones. He would arrange cones with different base radii arbitrarily on the floor and would admire the intrinsic beauty of the arrangement. The student even began theorizing about how som

poj 2932 Coneology(扫描线+set)

Coneology Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3574   Accepted: 680 Description A student named Round Square loved to play with cones. He would arrange cones with different base radii arbitrarily on the floor and would admire

poj 2932 Coneology (扫描线)

题意 平面上有N个两两不相交的圆,求全部最外层的,即不被其它圆包括的圆的个数并输出 思路 挑战程序竞赛P259页 代码 /* ********************************************** Auther: xueaohui Created Time: 2015-7-25 16:56:13 File Name : poj2932.cpp *********************************************** */ #include <iostr

POJ 2932 Coneology(扫描线)

[题目链接] http://poj.org/problem?id=2932 [题目大意] 给出N个两两没有公共点的圆,求所有不包含于其它圆内部的圆 [题解] 我们计算出所有点在圆心所有y位置的x值, 由于两两没有公共点,所以当我们对所有的x坐标进行扫描时,只要扫描相邻的x, 判定扫描到的圆和与其x相邻的圆是否是圆包含关系就可以判断一个圆的位置 扫描到左端点时,如果圆其被包含,则什么都不做,否则,将这个圆加入set中, 当扫描到右端点时,如果圆被包含,则什么都不做,否则将圆从set中去除. [代码

POJ 2932 Coneology (平面扫描)

Coneology Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3713   Accepted: 720 Description A student named Round Square loved to play with cones. He would arrange cones with different base radii arbitrarily on the floor and would admire

【BZOJ】1382: [Baltic2001]Mars Maps (线段树+扫描线)

1382: [Baltic2001]Mars Maps Time Limit: 5 Sec  Memory Limit: 64 MB Description 给出N个矩形,N<=10000.其坐标不超过10^9.求其面积并 Input 先给出一个数字N,代表有N个矩形. 接下来N行,每行四个数,代表矩形的坐标. Output 输出面积并 Sample Input 2 10 10 20 20 15 15 25 30 Sample Output 225 本以为是傻逼题,没想到不容易啊- 线段树+扫描

BZOJ 3022 [Balkan2012]The Best Teams(扫描线+线段树)

[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3022 [题目大意] 给定n个球员,第i个球员年龄为AGEi,水平为SKILLi. 没有任何两个球员的水平相同.将这些球员按水平排序, 对于一次比赛,你需要选择若干个球员去比赛,但不能同时选择两个水平相邻的球员. m次询问,每次给定a和k,表示要在年龄不超过a的球员中选择不超过k个球员, 请计算skill和的最大值. [题解] 对于询问年龄的限制,我们可以通过扫描线来处理. 我们将所有

【扫描线】Gym - 101190E - Expect to Wait

假设初始人数为0, 将每个时刻在等待的人数写下来,就是求个和. 如果纵坐标看成人数,横坐标看成时间,就是求个面积. 因为初始人数不一定为零,所以离线后扫描线即可回答所有询问. #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; int n,m,e; struct LINE{ int y,l,id; }ls[200010]; bool cmp(const LINE &a