Poj2932 coneology

扫描线+set

Posted by yjjr's blog on March 14, 2018

标签:扫描线

题目

题目传送门

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 dominate other 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 Ri, i = 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 Ri, xi, yi separated by spaces, where (xi, yi) 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

分析

题意:二维平面上由N个圆,给出圆心(Xi,Yi)和半径Ri。求所有最外层的,即不包含于其他圆内部的圆。

因为题目明确说不存在圆相交的情况,所以可以直接存储每个圆的左端点和右端点X的坐标

然后从左往右扫过去

如果扫描到一个圆的左端点,那么判断这个圆有没有被上下相邻的圆包含,如果没有就加入set

扫描到右端点的时候,把这个圆从set里删除就是了

code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define mp make_pair
#define pa pair<double,int>
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
//**********head by yjjr**********
const int maxn=4e4+6;
int n,cnt,ans;
bool mark[maxn];
double x[maxn],y[maxn],r[maxn];
pa l[maxn<<1];
set<pa> t;
set<pa>::iterator it;
inline bool contain(int a,int b){return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])<=r[b]*r[b];}

int main()
{
	n=read();
	rep(i,1,n)scanf("%lf%lf%lf",&r[i],&x[i],&y[i]);
	rep(i,1,n){
		l[++cnt]=mp(x[i]-r[i],i);
		l[++cnt]=mp(x[i]+r[i],i+n);
	}
	sort(l+1,l+1+cnt);
	rep(i,1,cnt){
		int now=l[i].second;
		if(now<=n){
			it=t.lower_bound(mp(y[now],now));
			if(it!=t.end()&&contain(now,it->second))continue;
			if(it!=t.begin()&&contain(now,(--it)->second))continue;
			mark[now]=1;ans++;
			t.insert(mp(y[now],now));
		}else t.erase(mp(y[now-n],now-n));
	}
	printf("%d\n",ans);
	rep(i,1,n)
		if(mark[i])printf("%d ",i);
	return 0;
}
本文可以转载,但必须附上原文链接,否则你会终生找不到妹子!!!欢迎关注我的CSDN: ahyjjr