题意:二维平面上给定n个整点,q个询问

每个询问给定另外的一个整点,问其能与n个整点中任意取2个组成的直角三角形的个数

保证所有点位置不同

n<=2e3,q<=2e3,abs(x[i],y[i])<=1e9

思路:

对于每个询问点q,分两类讨论

一:q为直角顶点

以q为原点,求出它到n个点的向量,极角排序

枚举一个向量,其贡献为平行于该向量逆时针转90度的向量的个数

二:q不为直角顶点

枚举直角顶点i作为原点,求出它到另外n-1个点的向量,极角排序

对于q,其贡献为:设t为i到q的向量,平行于t逆时针或顺时针转90度的向量的个数

用upper_bound-lower_bound计算个数

极度卡时,在HDOJ上TLE,在gym上4s时限3sA的

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
//typedef pair<ll,ll>P;
#define N 4100
#define M 2000010
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1 const ll MOD=1e9+,inv2=(MOD+)/;
double eps=1e-;
int INF=1e9;
int dx[]={-,,,};
int dy[]={,,-,}; struct P
{
int x,y;
P()=default;
P(int x,int y):x(x),y(y){}
P rot90(){return P(-y,x);} //逆时针转90度
P _rot90(){return P(y,-x);} //顺时针转90度
}p[N],t[N]; bool operator^(P a,P b) //叉积
{
return (1ll*a.x*b.y-1ll*a.y*b.x)>;
} int quadrant(P a) //象限
{
if(a.x>&&a.y>=) return ;
else if(a.x<=&&a.y>) return ;
else if(a.x<&&a.y<=) return ;
else if(a.x>=&&a.y<) return ;
} bool operator<(P a,P b) //极角排序
{
int qa=quadrant(a),qb=quadrant(b);
if(qa!=qb) return qa<qb;
return a^b;
} P operator-(P a,P b)
{
return P(a.x-b.x,a.y-b.y);
} int ans[N],n,q; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} void solve()
{
rep(i,,q) ans[i]=;
int m=n+q;
rep(i,n+,m)
{
int top=;
rep(j,,n)
{
top++;
t[top]=p[j]-p[i];
}
sort(t+,t+top+);
rep(j,,n)
{
P tmp=t[j].rot90();
int num=upper_bound(t+,t+top+,tmp)-lower_bound(t+,t+top+,tmp);
ans[i-n]+=num;
}
}
rep(i,,n)
{
int top=;
rep(j,,n)
if(j!=i)
{
top++;
t[top]=p[j]-p[i];
}
sort(t+,t+top+);
rep(j,n+,m)
{
P tmp=p[j]-p[i];
P t1=tmp.rot90();
ans[j-n]+=upper_bound(t+,t+top+,t1)-lower_bound(t+,t+top+,t1);
P t2=tmp._rot90();
ans[j-n]+=upper_bound(t+,t+top+,t2)-lower_bound(t+,t+top+,t2);
}
}
rep(i,,q) printf("%d\n",ans[i]);
} int main()
{
while(scanf("%d%d",&n,&q)!=EOF)
{
rep(i,,n+q) p[i].x=read(),p[i].y=read();
solve();
}
return ;
}

【HDOJ6731】Angle Beats(极角排序)的更多相关文章

  1. Angle Beats Gym - 102361A(计算几何)

    Angle Beats \[ Time Limit: 4000 ms \quad Memory Limit: 1048576 kB \] 题意 给出 \(n\) 个初始点以及 \(q\) 次询问,每次 ...

  2. Educational Codeforces Round 1 C. Nearest vectors 极角排序

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/ ...

  3. poj 2007 Scrambled Polygon 极角排序

    /** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...

  4. Space Ant(极角排序)

    Space Ant http://poj.org/problem?id=1696 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

  5. codeforces 598C C. Nearest vectors(极角排序)

    题目链接: C. Nearest vectors time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. LA-4356&&hdu-2469 (极角排序+扫描线)

    题目链接: Fire-Control System Time Limit: 12000/5000 MS (Java/Others)     Memory Limit: 32768/32768 K (J ...

  7. codeforces 1284E. New Year and Castle Construction(极角排序+扫描枚举)

    链接:https://codeforces.com/problemset/problem/1284/E 题意:平面上有n个点,问你存在多少组四个点围成的四边形 严格包围某个点P的情况.不存在三点共线. ...

  8. POJ 1696 Space Ant 【极角排序】

    题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完, ...

  9. Space Ant---poj1696(极角排序)

    题目链接:http://poj.org/problem?id=1696 题意:给你n个点,然后我们用一条线把它们连起来,形成螺旋状: 首先找到左下方的一个点作为起点,然后以它为原点进行极角排序,找到极 ...

随机推荐

  1. 重载Prometheus配置

    发送SIGHUP信号给应用程序的主进程: pid ‘’-1‘’是指“终端断线” 发送post请求给指定端点: curl -XPOST http://ip:9090/-/reload 对于此种方法要注意 ...

  2. 【Linux 环境搭建】ubuntu 的samba配置

    在/etc/samba/smb.conf的文件末尾增加下面的内容然后重启samba [home] comment = James Harden path = / browseable = yes wr ...

  3. [转帖]使用ping钥匙临时开启SSH:22端口,实现远程安全SSH登录管理就这么简单

    使用ping钥匙临时开启SSH:22端口,实现远程安全SSH登录管理就这么简单 https://www.cnblogs.com/martinzhang/p/5348769.html good good ...

  4. [转帖]Windows下cwRsyncServer双机连续同步部署

    Windows下cwRsyncServer双机连续同步部署 https://www.cnblogs.com/nulige/p/7607503.html 找时间做一下测试 应该能更好的实现 自动部署的功 ...

  5. 一分钟安装mysql

    学数据库的人都知道,MySQL数据库是比较基本的掌握要求,不仅开源而且社区版本是免费使用的.由于工作上或者经常更换系统的原因,有时候会需要安装MySQL数据库.为了不至于每次安装都要查阅资料,现把安装 ...

  6. [BZOJ3451]Normal(点分治+FFT)

    [BZOJ3451]Normal(点分治+FFT) 题面 给你一棵 n个点的树,对这棵树进行随机点分治,每次随机一个点作为分治中心.定义消耗时间为每层分治的子树大小之和,求消耗时间的期望. 分析 根据 ...

  7. 最大连续和 Medium

    Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous s ...

  8. 【问题解决方案】word2010中Mathtype公式偏上的问题解决

    参考百度百科 段落-中文版式-文本对齐方式-居中 END

  9. php设置错误级别

    ini_set('display_errors', 1); error_reporting(E_ALL);

  10. 命令行执行php脚本中的$argv和$argc配置方法

    在实际工作中有可能会碰到需要在nginx命令行执行php脚本的时候,当然你可以去配置一个conf用外网访问. 在nginx命令行中 使用 php index.php 就可以执行这个index.php脚 ...