题目链接https://codeforces.com/gym/102361/problem/A

题意:给定二维平面上的\(n\)个点,\(q\)次询问,每次加入一个点,询问平面上有几个包含该点的直角三角形。

分析:这是一篇鸽了很久的题解,主要原因就是现场赛的时候这题惨遭卡常,锅++。现在回过头来想这题,主要问题出在现场赛时误判了\(map\)的时间复杂度,把极角排序的正确想法成功叉掉,以及现场赛时候的共线计数使用了\(gcd\),使得整体复杂度上升。(但还是有大佬拿gcd思想过了,我太菜了)现在学了一种共线计数的新想法,只需要重载就能实现,于是再用\(map\)来写一写这道题。。。

本题思路不难,将直角三角形分为两类,一类是以新加入点为直角顶点的直角三角形,另一类新加入点不作直角顶点。第一种情况,我们将新加入点与原有点之间构成的所有向量加入\(map\),然后通过点积为零的性质查找垂直的向量个数。(会计数两次,要除以二)另一类采取离线操作,我们将每个原有点当作直角顶点遍历,并将该点与另外原有点构成的向量加入\(map\),更新\(q\)个新加入点的直角三角形数量即可。

AC代码

#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define SIZE 2010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
using namespace std;
struct Point {
ll x, y;
Point() {}
Point(ll a, ll b) :x(a), y(b) {}
Point base() const{
if (x < 0 || (x == 0 && y < 0))return Point(-x, -y);
return *this;
}
bool operator<(const Point& b)const {
Point p1 = base(); Point p2 = b.base(); //如果共线,考虑是相同的索引
return p1.x * p2.y < p1.y * p2.x;
}
void input() { scanf("%lld %lld", &x, &y); }
}p[SIZE];
Point operator *(Point a, ll t) { return Point(a.x * t, a.y * t); } //向量数乘
Point operator +(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); } //向量加法
Point operator -(Point a, Point b) { return Point(b.x - a.x, b.y - a.y); } //向量减法
Point operator / (Point a, ll p) { return Point(a.x / p, a.y / p); } //向量数乘的除法形式
double Polarangle(Point a) { return atan2(a.y, a.x); }
ll __gcd(ll a, ll b) { return b == 0 ? a : __gcd(b, a % b); }
int n, q, cnt = 1;
map<Point, int> MAP;
int main() {
scanf("%d %d", &n, &q);
int m = q;
vector<Point> vec(q + 1);
vector<int> res(q + 1);
rep(i, 1, n) p[i].input();
while (m--) {
int ans = 0; Point tp; tp.input();
vec[cnt] = tp;
rep(i, 1, n) {
Point tmp = p[i] - tp;
++MAP[tmp];
}
for (auto it : MAP) {
Point tmp(-it.first.y, it.first.x);
if (MAP.count(tmp)) ans += MAP[tmp] * it.second;
}
res[cnt++] = ans / 2;
MAP.clear();
}
rep(i, 1, n) {
MAP.clear();
rep(j, 1, n) {
if (i == j) continue;
MAP[p[j] - p[i]]++;
}
rep(j, 1, q) {
Point tp = vec[j] - p[i];
tp = Point(-tp.y, tp.x);
res[j] += MAP.count(tp) ? MAP[tp] : 0;
}
}
rep(i, 1, q) printf("%d\n", res[i]);
}

Codeforces Gym 102361A Angle Beats CCPC2019秦皇岛A题 题解的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  3. Codeforces Gym 100610 Problem E. Explicit Formula 水题

    Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  4. Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

    Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  5. Gym102361A Angle Beats(直角三角形 计算几何)题解

    题意: \(n\)个点,\(q\)个询问,每次问包含询问点的直角三角形有几个 思路: 代码: #include<bits/stdc++.h> using namespace std; co ...

  6. Codeforces Gym 100523C C - Will It Stop? 水题

    C - Will It Stop?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  7. Codeforces Round #796 (Div. 2)(A~E题题解)

    文章目录 原题链接: A.Cirno's Perfect Bitmasks Classroom 思路 代码 B.Patchouli's Magical Talisman 思路 代码 C.Manipul ...

  8. Codeforces Round #530 (Div. 2) (前三题题解)

    总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高 ...

  9. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

随机推荐

  1. Mac下Charles的安装和配置

    一.安装与破解 官网下载,破解方法参考其他,此处略 二.配置 1.电脑端安装 Charles 的根证书 注意:此时钥匙串默认为不信任,需设置为始终信任 2.配置代理:勾选enable transpre ...

  2. react 渲染

    目录 React渲染 createElement的三个参数 element如何生成真实节点 ReactDOMComponent 作用 ReactCompositeComponentWrapper 作用 ...

  3. 单位px和em,rem的区别

    px 相对长度单位.像素(Pixel). 像素是相对于显示器屏幕分辨率而言的.例如,WONDOWS的用户所使用的分辨率一般是96像素/英寸.而MAC的用户所使用的分辨率一般是72像素/英寸.(css手 ...

  4. 3ds Max File Format (Part 4: The first useful data; Scene, AppData, Animatable)

    The most interesting part of this file is, evidently, the Scene. Opening it up in the chunk parser, ...

  5. intermediate-python-for-data-science

    目录 matplotlib plot Scatter Plot histogram Customization Dictionaries, Part 1 Create dictionary dicti ...

  6. AcWing 1010. 拦截导弹

    //贪心加dp #include<iostream> using namespace std ; ; int n; int q[N]; int f[N]; int g[N];//存每个序列 ...

  7. 1052 Linked List Sorting (25分)

    题目 1. 思路 使用map存放所有的地址对 使用起始地址遍历map,结果存放在vector中 排序vector 输出vector 2. 注意点 开始的时候起始地址为-1 可能有些节点没有用到,注意排 ...

  8. 素问 - IC移仓换月

    摘自<小韭的学习圈> Q 股指期货的合约什么时候换月比较合适? 今天是1908股指期货的交割日,我是这么操作的:我在10:30分把IH1908以2827元卖出,然后马上以2805.8元买入 ...

  9. ASP.NET Razor简介

    Razor 不是一种编程语言.它是服务器端的标记语言. 什么是 Razor? Razor 是一种标记语法,可以让您将基于服务器的代码(Visual Basic 和 C#)嵌入到网页中. 基于服务器的代 ...

  10. 剑指offer 面试题. 滑动窗口的最大值

    题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值.例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6 ...