Codeforces Gym 102361A Angle Beats CCPC2019秦皇岛A题 题解
题目链接: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题 题解的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- 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 ...
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Gym102361A Angle Beats(直角三角形 计算几何)题解
题意: \(n\)个点,\(q\)个询问,每次问包含询问点的直角三角形有几个 思路: 代码: #include<bits/stdc++.h> using namespace std; co ...
- 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/ ...
- Codeforces Round #796 (Div. 2)(A~E题题解)
文章目录 原题链接: A.Cirno's Perfect Bitmasks Classroom 思路 代码 B.Patchouli's Magical Talisman 思路 代码 C.Manipul ...
- Codeforces Round #530 (Div. 2) (前三题题解)
总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高 ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
随机推荐
- C/C++ Windows API——获取系统指定目录(转)
原文地址:C/C++ Windows API——获取系统指定目录 经测试,在win10 VS2017中用wprintf()输出正常,SHGetSpecialFolderPath函数也正常运行 但是用M ...
- C++类this指针为空时的几个误区
代码: class test{ public: static void f1(){cout<<y<<endl;} void f2(){cout<<y<< ...
- 到头来还是逃不开Java - Java13核心类
Java13核心类 没有特殊说明,我的所有学习笔记都是从廖老师那里摘抄过来的,侵删 引言 兜兜转转到了大四,学过了C,C++,C#,Java,Python,学一门丢一门,到了最后还是要把Java捡起来 ...
- CSS的快速入门
CSS的快速入门 1.CSS要学习的内容主要包括 1. CSS概念和快速入门 2.CSS选择器(重点+难点) 3.美化网页(文字.阴影.超链接.列表.渐变,等) 4.盒子模型 5.浮动 6.定位 2. ...
- C语言预处理学习记录
#include<stdio.h> #define LOCAL //无参宏 //条件编译 #ifdef LOCAL int a=1; #else int a=2; #endif #ifnd ...
- 其他-使用 ProcessExplorer 定位 win10 系统资源占用
1. 概述 使用 ProcessExplorer 2. 环境 os win10 3. 背景 偶然在论坛上看到了一个工具 ProcessExplorer 作用是 定位当前桌面窗口 对应的 进程 我没有这 ...
- jQuery jqgrid
1.写div <div class="ibox-content"> <div class="jqGrid_wrapper"> <! ...
- 【译】使用 Rust 和 WebAssembly 构建离线画图页面
原文地址:https://dev.to/sendilkumarn/create-dev-s-offline-page-with-rust-and-webassembly-21gn 原文仓库:https ...
- 在Linux系统上安装Git
Git是目前流行的非常好用的版本控制工具,这里介绍两种安装方式,1.yum安装,2.从github上下载最新的源码编译后安装 一.yum安装 1.在Linux上是有yum安装Git,非常简单,只需要一 ...
- nvalidSchema: Missing dependencies for SOCKS support
首先需要安装pip3 1. 安装 setuptools wget --no-check-certificate https://pypi.python.org/packages/source/s/se ...