题意:

\(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. 1.5V升压3V集成电路升压芯片

    干电池1.5V升压3V的升压芯片,适用于干电池升压产品输出3V供电 1.5V输入时,输出3V,电流可达500MA. PW5100是一款效率大.10uA低功耗 PW5100输入电压:0.7V-5V PW ...

  2. PAT练习num2-挖掘机技术哪家强

    为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第 1 行给出不超过 1 的正整数 N,即参赛人数.随后 N 行, ...

  3. FPGA仿真的概念及语法特点

    以下是特权同学<FPGA设计+实战演练>书中的描述:      一个正规的设计需要花费在验证上的工作量,往往可能会占到整个开发流程的70%左右.验证通常分为仿真验证和板机验证.      ...

  4. ubuntu 更改U盘设备分区/dev/sdb4 标识

    备份u盘分区表 代码: sudo sfdisk -d /dev/sdb > sdb_table 修改sdb_table文件 代码: gedit sdb_table 恢复u盘分区表 代码: sud ...

  5. 第一个 IDEA 应用程序

    新建 Java Web 项目 打开 IDEA -> Create New Project 选择 Java -> Java EE -> Web Application 选择工作空间 项 ...

  6. 【LinuxShell】echo用法详解

    使用echo打印信息到终端 1 [Shell]echo "yz test" 2 yz test 3 [Shell]echo yz test 4 yz test 5 [Shell]e ...

  7. CF413C

    正文 题意: 给 n 个关卡,每个关卡得分为 ai,有 m 次机会可以选择一 个关卡通过后不得分,而将现有得分翻倍 你可以安排关卡的通过顺序和策略,求最大得分. 分析: 看到这道题首先想到的就是贪心, ...

  8. LOJ2436

    题目描述 幼儿园里有 N 个小朋友, lxhgww 老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到的糖果比他的多,于 ...

  9. Postman 的 Post 请求方式的四种类型的数据

    Postman 的 Post 请求方式的四种类型的数据 1. form-data 2. x-www-form-urlencoded 3. raw 4. binary 1. form-data 就是 H ...

  10. scala之map,List,:: , +:, :+, :::, +++操作

    scala之map,List操作 1.Map操作 2.List操作 2.1Demo1 2.2Demo2 3.:: , +:, :+, :::, +++ 1.Map操作 Map(映射)是一种可迭代的键值 ...