【扫描线】Gym - 100781G - Goblin Garden Guards

平面上有100000个哥布林和20000个圆,问你不在圆内的哥布林有多少个。

将每个圆从左到右切2r+1次,形成(2r+1)*2个端点,将上端点记作入点,下端点记作出点,再将这些点和那些哥布林一起排序(x第一关键字,y第二关键字,类型(入 哥布林 出)第三关键字),扫一遍就好了。

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double EPS=0.00000001;
struct Point{
	int x;
	double y;
	int type;
	Point(const int &x,const double &y,const int &type){
		this->x=x;
		this->y=y;
		this->type=type;
	}
	Point(){}
}p[405*20005+100005];
bool cmp(const Point &a,const Point &b){
	return a.x!=b.x ? a.x<b.x : (fabs(a.y-b.y)>=EPS ? a.y>b.y : a.type<b.type);
}
double sqr(double x){
	return x*x;
}
int n,m,e;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d%lf",&p[i].x,&p[i].y);
		p[i].type=1;
	}
	e=n;
	int x;
	double y,r;
	scanf("%d",&m);
	for(int i=1;i<=m;++i){
		scanf("%d%lf%lf",&x,&y,&r);
		for(int j=x-r;j<=x+r;++j){
			double tmp=r*r-sqr(x-(double)j);
			p[++e]=Point(j,sqrt(tmp)+y,0);
			p[++e]=Point(j,-sqrt(tmp)+y,2);
		}
	}
	sort(p+1,p+e+1,cmp);
	int in=0,ans=0;
	for(int i=1;i<=e;++i){
		if(p[i].type==0){
			++in;
		}
		else if(p[i].type==2){
			--in;
		}
		else{
			if(in==0){
				++ans;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

转载于:https://www.cnblogs.com/autsky-jadek/p/7219612.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值