题目链接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. eureka server 单节点与多节点部署演示

    环境搭建 目录结构(ad-eureka为子模块) --ad-spring-cloud --ad-eureka --pom.xml --pom.xml 主pom.xml <?xml version ...

  2. Oracle11g配置监听

    步骤 1.在windows系统上安装好Oracle后,点击右下角开始菜单Oracle目录下选择Net Manager进行配置,也可以使用Net Configuration Assistant(建议使用 ...

  3. js中的闭包理解

    闭包是一个比较抽象的概念,尤其是对js新手来说.书上的解释实在是比较晦涩,对我来说也是一样. 但是他也是js能力提升中无法绕过的一环,几乎每次面试必问的问题,因为在回答的时候.你的答案的深度,对术语的 ...

  4. Introduction to Writing Functions in R

    目录 在R中编写函数 args(函数名) 创建一个函数的步骤 1.default args Passing arguments between functions Checking arguments ...

  5. 使用listView有感

    et listView = new ccui.ListView();this.addChild(listView,9999);listView.setDirection(ccui.ScrollView ...

  6. os和sys模块_python

    一.os模块 1.os模块的功能 提供对系统调用的借口,常用于系统文件目录打交道. 2.常用的方法 二.sys模块 1.模块功能 与python解释器交互 2.常用方法 print(sys.path) ...

  7. windows下tesseract-ocr的安装及使用

    For CentOS 7 run the following as root: yum-config-manager --add-repo https://download.opensuse.org/ ...

  8. Android基础知识 -- Fragment

    Fragment是android3.0后提供的API(所以android:minSdkVersion="11"以上版本),主要针对平板UI.有自己的生命周期,但是必须依附在Acti ...

  9. python3练习100题——026

    原题链接:http://www.runoob.com/python/python-exercise-example26.html 题目:利用递归方法求5!. 是25题递归方式的简化版所以很容易. 我的 ...

  10. python3 求一个list的所有子集

    python3 求一个list的所有子集 def PowerSetsBinary(items): N = len(items) for i in range(2 ** N):#子集的个数 combo ...