题意:

\(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. python--or 和 and 表达式

    or表达式: 两边为一真一假,返回真: 两边都为假,返回右边: 两边都为真,返回左边: and表达式: 两边为一真一假,返回假: 两边都为假,返回左边: 两边都为真,返回右边:

  2. 前端知识(一)03 初识 ECMAScript 6-谷粒学院

    目录 一.ECMAScript 6 1.什么是 ECMAScript 6 2.ECMAScript 和 JavaScript 的关系 二.基本语法 1.let声明变量 2.const声明常量(只读变量 ...

  3. Vue使用Ref跨层级获取组件实例

    目录 Vue使用Ref跨层级获取组件实例 示例介绍 文档目录结构 安装vue-ref 根组件自定义方法[使用provide和inject] 分别说明各个页面 结果 Vue使用Ref跨层级获取组件实例 ...

  4. Python爬虫学习笔记(一)

    概念: 使用代码模拟用户,批量发送网络请求,批量获取数据. 分类: 通用爬虫: 通用爬虫是搜索引擎(Baidu.Google.Yahoo等)"抓取系统"的重要组成部分. 主要目的是 ...

  5. java虚拟机入门(二)-探索内存世界

    上节简单介绍了一下jvm的内存布局以及简单概念,那么对于虚拟机来说,它是怎么一步步的让我们能执行方法的呢: 1.首先,jvm启动时,跟个小领导一样会根据配置参数(没有配置的话jvm会有默认值)向大领导 ...

  6. moco框架实现重定向

    一.重定向到百度 1.代码 2.运行结果 因为没哟填写别的,浏览器输入路径: localhost:8888/redirect 点击回车,跳转到百度 二.跳转到自己的网站 1.代码 2.运行结果 输入准 ...

  7. JVM虚拟机垃圾回收(GC)算法及优缺点

    一.什么是GC   GC是jvm的垃圾回收,垃圾回收的规律和原则为:   次数上频繁收集新生区(Young)   次数上较少收集养老区(Old)   基本上不动永久区(Perm) 二.GC算法(分代收 ...

  8. BBR implements bbr-like limiter 限流

    pkg/ratelimit/bbr/bbr.go:68 github.com/go-kratos // BBR implements bbr-like limiter.// It is inspire ...

  9. Go Code Review Comments

    Go Code Review Comments https://golang.org/wiki/CodeReviewComments

  10. 一个关于ExecutorService shutdownNow时很奇怪的现象

    我们知道很多类库中的阻塞方法在抛出InterruptedException后会清除线程的中断状态(例如 sleep. 阻塞队列的take),但是今天却发现了一个特别奇怪的现象,先给出代码: publi ...