题意:

\(n\)个点,\(q\)个询问,每次问包含询问点的直角三角形有几个

思路:

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 8000 + 10;
typedef long long ll;
const ll mod = 998244353;
typedef unsigned long long ull;
struct Point{
ll x, y;
int flag;
}be[maxn], p[maxn];
int Qua(Point a){
if(a.x > 0 && a.y >= 0) return 1;
if(a.x <= 0 && a.y > 0) return 2;
if(a.x < 0 && a.y <= 0) return 3;
if(a.x >= 0 && a.y < 0) return 4;
}
int cmp1(Point a, Point b) {
ll d = a.x * b.y - b.x * a.y;
if(d == 0) {
return a.x < b.x;
}
else{
return d > 0;
}
}
bool cmp(const Point &a, const Point &b){
int qa = Qua(a), qb = Qua(b);
if(qa == qb){
return cmp1(a, b);
}
return qa < qb;
}
int angle(Point a, Point b){ //爆ll
ull now = (ull)(a.x - b.x) * (a.x - b.x) + (ull)(a.y - b.y) * (a.y - b.y);
ull exc = a.x * a.x + a.y * a.y + b.x * b.x + b.y * b.y;
if(now == exc) return 0; //直角
if(now < exc) return -1; //锐角
return 1; //钝角
}
ll cross(Point a, Point b){
return a.x * b.y - a.y * b.x;
}
ll ans[maxn];
int main(){
int n, q;
scanf("%d%d", &n, &q);
int cnt = 0;
for(int i = 1; i <= n; i++){
cnt++;
scanf("%lld%lld", &be[cnt].x, &be[cnt].y);
be[cnt].flag = 0;
p[cnt] = be[cnt];
}
for(int i = 1; i <= q; i++){
cnt++;
scanf("%lld%lld", &be[cnt].x, &be[cnt].y);
be[cnt].flag = i;
p[cnt] = be[cnt];
} for(int i = n + 1; i <= cnt; i++){
p[0] = be[i]; //直角点
int tot = 0;
for(int j = 1; j <= n; j++){
p[j].x = be[j].x - be[i].x;
p[j].y = be[j].y - be[i].y;
p[j].flag = be[j].flag;
}
sort(p + 1, p + n + 1, cmp);
for(int j = 1; j <= n; j++){
p[j + n] = p[j];
} int R = 2;
for(int L = 1; L <= n; L++){
while(R <= 2 * n){
if(cross(p[L], p[R]) < 0) break;
if(angle(p[L], p[R]) >= 0) break;
R++;
}
int tR = R;
while(tR <= 2 * n){
if(cross(p[L], p[tR]) <= 0) break;
if(angle(p[L], p[tR]) != 0) break;
ans[be[i].flag]++;
tR++;
}
}
} for(int i = 1; i <= n; i++){
p[0] = be[i]; //非直角点
int tot = 0;
for(int j = 1; j <= cnt; j++){
if(j == i) continue;
tot++;
p[tot].x = be[j].x - be[i].x;
p[tot].y = be[j].y - be[i].y;
p[tot].flag = be[j].flag;
}
sort(p + 1, p + tot + 1, cmp);
for(int j = 1; j <= tot; j++){
p[j + tot] = p[j];
} int R = 2;
for(int L = 1; L <= tot; L++){
while(R <= 2 * tot){
if(cross(p[L], p[R]) < 0) break;
if(angle(p[L], p[R]) >= 0) break;
R++;
}
int tR = R;
while(tR <= 2 * tot){
if(cross(p[L], p[tR]) <= 0) break;
if(angle(p[L], p[tR]) != 0) break;
if(p[L].flag && p[tR].flag == 0){
ans[p[L].flag]++;
}
else if(p[L].flag == 0 && p[tR].flag){
ans[p[tR].flag]++;
}
tR++;
}
}
} for(int i = 1; i <= q; i++) printf("%lld\n", ans[i]); return 0;
}

Gym102361A Angle Beats(直角三角形 计算几何)题解的更多相关文章

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

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

  2. Codeforces Gym 102361A Angle Beats CCPC2019秦皇岛A题 题解

    题目链接:https://codeforces.com/gym/102361/problem/A 题意:给定二维平面上的\(n\)个点,\(q\)次询问,每次加入一个点,询问平面上有几个包含该点的直角 ...

  3. hdu6731 Angle Beats(ccpc秦皇岛A,计算几何)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6731 题意: 给出$n$个点,有$q$次询问 每次询问给出一个点$b$,求这$n+1$个点,组成直角 ...

  4. CCPC 2019 秦皇岛 Angle Beats

    题目 给出P个点,然后给出Q个询问,问从P中选出两个点和给的点能组成直角三角形的方法个数.-O2,时间限制5秒. \[2\leqslant P\leqslant 2000,\qquad 1\leqsl ...

  5. Angle Beats Gym - 102361A

    题目链接:https://vjudge.net/problem/Gym-102361A 题意:给定N个点,q次询问每次询问给一个点,问在N个点中取2个和给定点最多可以组成几个直角三角形. 思路:htt ...

  6. 【HDOJ6731】Angle Beats(极角排序)

    题意:二维平面上给定n个整点,q个询问 每个询问给定另外的一个整点,问其能与n个整点中任意取2个组成的直角三角形的个数 保证所有点位置不同 n<=2e3,q<=2e3,abs(x[i],y ...

  7. UVa 1643 Angle and Squares (计算几何)

    题意:有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值. 析:很容易知道只有所有的正方形的对角形在一条直线时,是最大的,然后根据数学关系,就容易得 ...

  8. 300iq Contest 1 简要题解

    300iq Contest 1 简要题解 咕咕咕 codeforces A. Angle Beats description 有一张\(n\times m\)的方阵,每个位置上标有*,+,.中的一种. ...

  9. jrMz and angles(水题)

    jrMz and angles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

随机推荐

  1. ASP.NET Core错误处理中间件[4]: 响应状态码页面

    StatusCodePagesMiddleware中间件与ExceptionHandlerMiddleware中间件类似,它们都是在后续请求处理过程中"出错"的情况下利用一个错误处 ...

  2. [Usaco2016 Dec]Moocast

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4749 可以对于每个点\(i\),往跟\(i\)距离小于等于\(p[i]\)的点\(j\)都 ...

  3. 从JAVA内存到垃圾回收,带你深入理解JVM

    摘要:学过Java的程序员对JVM应该并不陌生,如果你没有听过,没关系今天我带你走进JVM的世界.程序员为什么要学习JVM呢,其实不懂JVM也可以照样写出优质的代码,但是不懂JVM有可能别被面试官虐得 ...

  4. vue-cli快速创建项目,可视化创建

    之前学习了交互式创建,发现过程无聊,而且不方便,后面又学习了图形可视化创建,下面进行分享 1.打开cmd 2.输入vue ui,输入后会出现如下 C:\Users\12235>vue ui St ...

  5. 理想的DevOp流程怎么做?看看Slack的代码部署实践 原创 Michael Deng 高可用架构 今天

    理想的DevOp流程怎么做?看看Slack的代码部署实践 原创 Michael Deng  高可用架构  今天

  6. new() 和 make() 的区别 var arr1 = new([5]int) var arr2 [5]int

    Effective Go - The Go Programming Language https://golang.org/doc/effective_go.html#allocation_new A ...

  7. 游戏寻路A*算法

    A*算法是一种启发式的BFS,目的就是找到到达目标位置的最短路径.启发式函数如下: f(x) = g(x) + h(x) g(x)是对出发点到达当前点距离的估约,h(x)是当前点到终点距离的估约.算法 ...

  8. Wireshark抓包参数

    目录 wireshark 抓包过滤器 一.抓包过滤器 二.显示过滤器 整理自陈鑫杰老师的wireshark教程课 wireshark 抓包过滤器 过滤器分为抓包过滤器和显示过滤器,抓包过滤器会将不满足 ...

  9. 理解和运用 ClassLoader 该篇文章就够了

    定义 根据<深入理解Java虚拟机>提到"通过一个类的全限定名(packageName.ClassName)来获取描述此类的二进制字节(class文件字节)这个动作的代码模块就叫 ...

  10. 最短路-Bellmm-ford算法

    Bellmm-ford算法 解决什么样的问题 有边数限制的最短路,存在负权边,负环 概念 通俗的来讲就是:假设 1 号点到 n 号点是可达的,每一个点同时向指向的方向出发,更新相邻的点的最短距离,通过 ...