2015 北京网络赛 C Protecting Homeless Cats hihoCoder 1229 树状数组
题意:求在平面上 任意两点连线,原点到这个点的距离小于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 树状数组的更多相关文章
- 沈阳网络赛J-Ka Chang【分块】【树状数组】【dfs序】
Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, ...
- 2015北京网络赛 A题 The Cats' Feeding Spots 暴力
The Cats' Feeding Spots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acm ...
- 2019南昌网络赛I:Yukino With Subinterval(CDQ) (树状数组套主席树)
题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 思路:46min交了第一发树套树,T了. 稍加优化多交几次就过了. 不难想到,除了L这个点, ...
- 2015北京网络赛A题The Cats' Feeding Spots
题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. #include ...
- 2019南昌网络赛 I. Yukino With Subinterval 树状数组套线段树
I. Yukino With Subinterval 题目链接: Problem Descripe Yukino has an array \(a_1, a_2 \cdots a_n\). As a ...
- 2019ICPC 上海网络赛 L. Digit sum(二维树状数组+区间求和)
https://nanti.jisuanke.com/t/41422 题目大意: 给出n和b,求1到n,各数在b进制下各位数之和的总和. 直接暴力模拟,TLE.. 没想到是要打表...还是太菜了. # ...
- 2015北京网络赛 Couple Trees 倍增算法
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
- 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 ...
- 2015北京网络赛 J Scores bitset+分块
2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...
随机推荐
- 消息中间件系列四:RabbitMQ与Spring集成
一.RabbitMQ与Spring集成 准备工作: 分别新建名为RabbitMQSpringProducer和RabbitMQSpringConsumer的maven web工程 在pom.xml文 ...
- NuGet Packages are missing,This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.
错误内容 This project references NuGet package(s) that are missing on this computer. Use NuGet Package R ...
- 2. ansible-playbook 条件语句-内部变量使用
内部变量指的是把变量定义在playbook里面或者是执行结果作为变量 循环语句-标准Loops [root@LeoDevops playb]# cat p_loop.yaml - hosts: u12 ...
- [Vue warn]: Attribute "id" is ignored on component <div> because the component is a fragment instanc
今天在使用vue框架搭建环境时,遇到这个错误提示: [Vue warn]: Attribute "id" is ignored on component <div> b ...
- 【C++/类与对象总结】
1.以上是对本章知识的大致梳理,下面通过我自己在编程中遇到的问题再次总结. 私有成员必须通过get()函数访问吗?能不能直接调用? 私有成员必须通过公共函数接口去访问,比如设置set()修改成员内容, ...
- C++ 中文拼音排序方法。
参考文档:http://zisxks.com/2013/10/25/sort-Chinese-characters-in-cpp/ 采用locate.注意事项:排序的名字,如果出现某一个人,出现在顶上 ...
- elk-filebeat-(效果图示)(四)
一.vim filebeat-6.3.2-linux-x86_64/filebeat.yml - type: log # Change to true to enable this input con ...
- tuple的基本使用
常用如下所示: # 元祖,tuple-->不可变,但元祖里面的数据可以变化 # 当元祖只有一个元素时,需加’,‘,否则类型是<class 'int'> # tuple1 = (1) ...
- linux中的pwd
https://www.cnblogs.com/crazylqy/p/5818745.html
- bootstrap-treeview 中文开发手册
官方文档URL: https://www.npmjs.com/package/bootstrap-treeview 2017年11月21日10:45:10 演示:http://www.htmleaf ...