题意:二维平面上给定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. 针对WordPress站点思路

    一.使用WPscan 1).简介 WPScan是一个扫描 WordPress 漏洞的黑盒子扫描器,它可以为所有 Web 开发人员扫描 WordPress 漏洞并在他们开发前找到并解决问题.我们还使用了 ...

  2. 20191127 Spring Boot官方文档学习(4.10)

    4.10.使用SQL数据库 从使用JdbcTemplate直接的JDBC访问到完整的"对象关系映射"技术(例如Hibernate),Spring框架为使用SQL数据库提供了广泛的支 ...

  3. kafka之config/server.properties配置参数说明

    broker.id--服务器编号 host.name--推荐写本机ip advertised.host.name--外网访问ip advertised.port--外网访问端口 num.partiti ...

  4. Simplify Path(路径简化)

    问题: 来源:https://leetcode.com/problems/simplify-path Given an absolute path for a file (Unix-style), s ...

  5. 部署CM集群首次运行报错:Formatting the name directories of the current NameNode.

    1. 报错提示 Formatting the name directories of the current NameNode. If the name directories are not emp ...

  6. HNUSTOJ 1601:名字缩写

    1601: 名字缩写 时间限制: 1 Sec  内存限制: 128 MB 提交: 288  解决: 80 [提交][状态][讨论版] 题目描述 Noname老师有一个班的学生名字要写,但是他太懒了,想 ...

  7. django的模板的继承与导入

    1.模板继承 母版中需要继承的地方: {% block content %} {% endblock %} 对应的子版中文件最开头写: {% extends 'head_demo.html' %} 然 ...

  8. 如何将DataTable转换成List<T>

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  9. js中的数组去掉空值

    //result 是有空值的数组//r是处理好的数组var r = result.filter(function (s) { return s && s.trim();});

  10. Mongo --01 介绍、安装、优化报警

    目录 一 . NoSQL 介绍 二.MongoDB简介 三.MongoDB特点 四. mongo应用场景 五. 安装配置mongodb 六.优化报警 一 . NoSQL 介绍 NoSQL,指的是非关系 ...