题意:求在平面上 任意两点连线,原点到这个点的距离小于d的点对有多少个,n=200000;

解: 以原点为圆心做一个半径为d的圆,我们知道圆内的点和园内以外的点的连线都是小于d的还有,圆内和园内的点联线也是小于d的,那么需要处理的是圆外和圆外的点。

以每个圆外的点 向圆做切线 然后我们知道有绿色点区域是允许和他搭配的

那么这些点有一个共同特点 那就他们和圆的切线都在 那个点切点的一侧,这样我们就让每个点 转化为两个切点,然后按照极角排序,求出那些不想交区间就是不合法的

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn=*;
const double eps=0.000000000001;
const double PI=acos(-1.0);
struct Point
{
double x,y;
Point(double cx=,double cy=)
{
x=cx; y=cy;
}
};
struct Circle{
Point c;
double r;
Circle(Point c,double r):c(c),r(r){}
Point point(double a)
{
return Point(c.x+cos(a)*r,c.y+sin(a)*r);
}
};
int dcmp(double a)
{
if(fabs(a)<eps)return ;
return a<?-:;
}
double angle(Point v)
{
return atan2(v.y,v.x);
}
Point operator -(Point A, Point B)
{
return Point(A.x-B.x,A.y-B.y);
}
double Length(Point c)
{
return sqrt(c.x*c.x+c.y*c.y);
}
Point Rotate(Point A, double rad)
{
return Point(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
void getTangents(Point p, Circle C,double &A, double &B)
{
Point u=p;
double dist=Length(u);
if(dcmp(dist-C.r)==){
double a=atan2(p.y,p.x);
if(a<){
B=A=a+PI*;
}else A=B=a;
}else{
double ang=acos(C.r/dist);
Point t=Rotate(u,ang);
double a=atan2(t.y,t.x);
if(a<)
{
A=a+PI*;
B=a-ang*+PI*;
}else{
A=a;
B=a-ang*;
if(B<)B+=PI*;
}
}
}
Point P[maxn];
struct Elem
{
double L,R;
int cL,cR;
bool operator <(const Elem &rhs)const
{
return cL<rhs.cL||(cL==rhs.cL&&cR<rhs.cR);
}
}E[maxn];
double JJ[maxn*];
int C[maxn*];
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int v,int n)
{
if(x<=)return ;
while(x<=n)
{
C[x]+=v;
x+=lowbit(x);
}
}
int sum(int x)
{
int ans=;
while(x>)
{
ans+=C[x];
x-=lowbit(x);
}
return ans;
}
int main()
{
int n;
double d;
while(scanf("%d%lf",&n,&d)==)
{
LL ge=,nu=,cc=;
Circle c(Point(,),d);
for(int j=; j<n; j++)
{
scanf("%lf%lf",&P[nu].x,&P[nu].y);
if(dcmp(Length(P[nu])-d)<)
{
ge++;
}
else
{
getTangents(P[nu],c,E[nu].L,E[nu].R);
if(E[nu].L>E[nu].R)swap(E[nu].L,E[nu].R);
JJ[cc++]=E[nu].L;JJ[cc++]=E[nu].R;
nu++;
}
}
sort(JJ,JJ+cc);
ge=;
for(int i=; i<cc; i++)
{
if(dcmp(JJ[i]-JJ[ge-])>)JJ[ge++]=JJ[i];
}
cc=ge;
for(int i=; i<=cc; i++)C[i]=;
for(int i=; i<nu; i++)
{
E[i].cL=upper_bound(JJ,JJ+cc,E[i].L)-JJ;
E[i].cR=upper_bound(JJ,JJ+cc,E[i].R)-JJ;
add(E[i].cL,,cc);
add(E[i].cR,-,cc);
}
sort(E,E+nu);
LL buhefa=;
for(int i=; i<nu; i++)
{
LL d1= sum(E[i].cR);
LL d2= sum(E[i].cL-);
buhefa+=d1-d2;
add(E[i].cL,-,cc);
add(E[i].cR,,cc);
}
LL nn=n;
LL ans=nn*(nn-)/-buhefa;
printf("%lld\n",ans);
}
return ;
}
/*
4 10
0 2
2 0
0 100
100 0
*/
 

2015 北京网络赛 C Protecting Homeless Cats hihoCoder 1229 树状数组的更多相关文章

  1. 沈阳网络赛J-Ka Chang【分块】【树状数组】【dfs序】

    Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, ...

  2. 2015北京网络赛 A题 The Cats' Feeding Spots 暴力

    The Cats' Feeding Spots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acm ...

  3. 2019南昌网络赛I:Yukino With Subinterval(CDQ) (树状数组套主席树)

    题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 思路:46min交了第一发树套树,T了. 稍加优化多交几次就过了. 不难想到,除了L这个点, ...

  4. 2015北京网络赛A题The Cats' Feeding Spots

    题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. #include ...

  5. 2019南昌网络赛  I. Yukino With Subinterval 树状数组套线段树

    I. Yukino With Subinterval 题目链接: Problem Descripe Yukino has an array \(a_1, a_2 \cdots a_n\). As a ...

  6. 2019ICPC 上海网络赛 L. Digit sum(二维树状数组+区间求和)

    https://nanti.jisuanke.com/t/41422 题目大意: 给出n和b,求1到n,各数在b进制下各位数之和的总和. 直接暴力模拟,TLE.. 没想到是要打表...还是太菜了. # ...

  7. 2015北京网络赛 Couple Trees 倍增算法

    2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道.  解法来自 q ...

  8. 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT

    2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...

  9. 2015北京网络赛 J Scores bitset+分块

    2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...

随机推荐

  1. 在Ubuntu主机下实现与Windows虚拟机共享文件夹

    一.概述 由于要实现Ubuntu主机中的一些文件与Windows虚拟机共享,因此要创建一个共享文件夹映射到虚拟机中. 网上许多都是Windows主机+Linux虚拟机的配置,在此分享主机是Linux的 ...

  2. git 中merge的用法

    git merge –no-ff 可以保存你之前的分支历史.能够更好的查看 merge历史,以及branch 状态. git merge 则不会显示 feature,只保留单条分支记录.

  3. C# SQLite数据库

    在客户端配置文件<configuration>节点下,添加: <connectionStrings> <add name="localdb" conn ...

  4. Windows上使用telnet测试端口号

    之前测试服务器某一端口开启开启情况一般在服务器上使用  netstat –ano|findstr "端口号"命令查看. 但是有时候端口在服务器上开通了,但是客户端并不一定可以访问到 ...

  5. Qt编写自定义控件9-导航按钮控件

    前言 导航按钮控件,主要用于各种漂亮精美的导航条,我们经常在web中看到导航条都非常精美,都是html+css+js实现的,还自带动画过度效果,Qt提供的qss其实也是无敌的,支持基本上所有的CSS2 ...

  6. Scala函数使用可变参数

    scala同java一样,在定义函数的时候支持接收可变长参数列表,即最后一个参数的可以被重复.示例代码如下: 结果: 在此代码中我们定义函数printInfo接收变长参数列表,其最后一个参数names ...

  7. js---根据指定的顺序进行排序

    有一个数据列表,我需要根据根据ID依次来取里面的第9,3,8,4项,具体的实现方法. var arr = [ {id:1,title:'我是第一个'}, {id:2,title:'我是第二个'}, { ...

  8. zhenya moves from parents

    Zhenya moved from his parents' home to study in other city. He didn't take any cash with him, he onl ...

  9. 发送消息-配置app_id

    $user_id = $curr_workitem["creater_id"]; $user_name = g('dao_user') -> get_by_id($user_ ...

  10. js 图片与base64互相转换

    js将图片转化为base64 参考地址:http://www.cnblogs.com/mr-wuxiansheng/p/6931077.html var img = "imgurl" ...