要点

  • 用A、B、C一般式确定每条直线
  • 将合法的圆心中点存到每条直线所属的vector中
  • 枚举所有线段,二分后\(O(1)\)得到其中存在多少答案,累加
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <unordered_map>
using namespace std; typedef long long ll;
const int maxn = 3e5 + 5, maxm = 1550;
const ll inf = 1e18; struct Point {
ll x, y;
Point() {}
Point(ll a, ll b):x(a), y(b) {}
};
struct Circle {
Point p;
ll r;
Circle() {}
Circle(Point a, ll b):p(a), r(b) {}
}; int n, m, hashcnt;
Point a[maxn], b[maxn];//segments
Circle c[maxm];//circles
unordered_map<ll, int> mp;//<{A, B, C}, id>
vector<ll> v[maxn];//v[id]
ll A, B, C;//a few times used
ll ans;
int ID[maxn]; ll sqr(ll x) {
return x * x;
} ll dis(int i, int j) {//distance ^ 2
return sqr(c[i].p.x - c[j].p.x) + sqr(c[i].p.y - c[j].p.y);
} ll gcd(ll a, ll b) {//exist zero: return
if (!a || !b) return a + b;
return gcd(b, a % b);
} ll Cross(Point A, Point B) {
return A.x * B.y - A.y * B.x;
} void Deal(ll &A, ll &B, ll &C) {//unique the line
ll q = gcd(gcd(abs(A), abs(B)), abs(C));
A /= q, B /= q, C /= q;
if (A == 0 && B < 0) B = -B, C = -C;
else if (A < 0) A = -A, B = -B, C = -C;
} ll hashi(ll A, ll B, ll C) {//map is TLE, so I hash it
return A * (ll)(1e12) + B * (ll)(1e6) + C;
} void Hash(int i, ll A, ll B, ll C) {
ll d = hashi(A, B, C);
if (!mp.count(d)) {
mp[d] = ++hashcnt;
}
int id = mp[d];
ID[i] = id;
} void calc(Point a, Point b) {// get A, B, C
A = b.y - a.y, B = a.x - b.x;
C = Cross(b, a);//Ax + By + C = 0
Deal(A, B, C);
} int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%lld %lld %lld %lld", &a[i].x, &a[i].y, &b[i].x, &b[i].y);
a[i].x *= 2, a[i].y *= 2, b[i].x *= 2, b[i].y *= 2;//for line 99
if (a[i].x > b[i].x) swap(a[i], b[i]);//for line 109 & 110
calc(a[i], b[i]);
Hash(i, A, B, C);
}
for (int i = 1; i <= m; i++) {
scanf("%lld %lld %lld", &c[i].p.x, &c[i].p.y, &c[i].r);
c[i].p.x *= 2, c[i].p.y *= 2, c[i].r *= 2;
for (int j = 1; j < i; j++)
if (c[i].r == c[j].r && dis(i, j) > 4LL * sqr(c[i].r)) {//if eyes
calc(c[i].p, c[j].p);
ll A1 = B * 2, B1 = -A * 2;
ll C1 = A * (c[i].p.y + c[j].p.y) - B * (c[i].p.x + c[j].p.x);
Deal(A1, B1, C1);
ll d = hashi(A1, B1, C1);
if (!mp.count(d)) continue;
ll x = (c[i].p.x + c[j].p.x) / 2;//line 99: should avoid double
v[mp[d]].emplace_back(x);
}
}
for (int i = 1; i <= hashcnt; i++) {
v[i].emplace_back(inf);
sort(v[i].begin(), v[i].end());
}
for (int i = 1; i <= n; i++) {
int id = ID[i];
int l = lower_bound(v[id].begin(), v[id].end(), a[i].x) - v[id].begin();//line 109
int r = upper_bound(v[id].begin(), v[id].end(), b[i].x) - v[id].begin();//line 110
ans += r - l;
}
return !printf("%lld\n", ans);
}

Codeforces 350D(计算几何)的更多相关文章

  1. Codeforces Gym100543B 计算几何 凸包 线段树 二分/三分 卡常

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF-Gym100543B.html 题目传送门 - CF-Gym100543B 题意 给定一个折线图,对于每一条 ...

  2. Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何

    C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...

  3. Codeforces 749B:Parallelogram is Back(计算几何)

    http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...

  4. Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何

    A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got ...

  5. Codeforces Round #524 (Div. 2) C. Masha and two friends(思维+计算几何?)

    传送门 https://www.cnblogs.com/violet-acmer/p/10146350.html 题意: 有一块 n*m 的棋盘,初始,黑白块相间排列,且左下角为白块. 给出两个区间[ ...

  6. Codeforces 528E Triangles 3000 - 计算几何

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定$n$的平面上的直线,保证没有三条直线共点,两条直线平行.问随机选出3条直线交成的三角形面积的期望. 显然$S=\frac{1}{2}ah ...

  7. Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何

    A. Crazy Town 题目连接: http://codeforces.com/contest/498/problem/A Description Crazy Town is a plane on ...

  8. Codeforces Round #357 (Div. 2) E. Runaway to a Shadow 计算几何

    E. Runaway to a Shadow 题目连接: http://www.codeforces.com/contest/681/problem/E Description Dima is liv ...

  9. Codeforces Beta Round #1 C. Ancient Berland Circus 计算几何

    C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description Nowadays a ...

随机推荐

  1. codeforces914G Sum the Fibonacci

    题目大意:给定一个长为$n$($n\leq 10^6$)的序列S,定义一个合法的五元组$(a,b,c,d,e)$合法当且仅当 $$ ( S_a \mid S_b ) and S_c and ( S_d ...

  2. 解决mysql 客户端连接问题

        问题:在linux 上安装了mysql服务端,使用客户端连接时报错信息为:ERROR 1045 (28000): Access denied for user 'root'@'localhos ...

  3. spring IOC 注解@Resource

    1.@Resource(重要)a)加入 :j2ee/common-annotations.jar b)默认按名称,名称找不到,按类型 默认按照名称setName1到xml中找和id相同的,没有的话再找 ...

  4. [转]Unity3D学习笔记(四)天空、光晕和迷雾

    原文地址:http://bbs.9ria.com/thread-186942-1-1.html 作者:江湖风云 六年前第一次接触<魔兽世界>的时候,被其绚丽的画面所折服,一个叫做贫瘠之地的 ...

  5. Angular面试题

    1. ng-show/ng-hide 与 ng-if的区别? 我们都知道ng-show/ng-hide实际上是通过display来进行隐藏和显示的.而ng-if实际上控制dom节点的增删除来实现的.因 ...

  6. idea2016 64位 安装,jdk环境变量配置

      idea 激活服务器地址: 地址1: http://www.iteblog.com/idea/key.php     地址2:  http://idea.qinxi1992.cn/ intelli ...

  7. 我的笔记文档版本控制系统-MediaWiki-回到顶部/链接放大/升级

    为了练习自己的JS.CSS基本功,这些天和MediaWiki干上了!^_^ 下面是我的MediaWiki新添加的功能: 回到顶部 链接放大 MediaWiki升级 回到顶部 回到顶部是很多网站的基本功 ...

  8. 一款Regular expression在线检测工具

    记录下我自己使用的一款正则表达式使用工具 https://regex101.com/ 输入正则表达式后,可以在下面的“TEST STRING”中来测试对应的字符串是否满足该正则表达式 个人觉得非常好用

  9. 简单Hadoop集群环境搭建

    最近大数据课程需要我们熟悉分布式环境,每组分配了四台服务器,正好熟悉一下hadoop相关的操作. 注:以下带有(master)字样为只需在master机器进行,(ALL)则表示需要在所有master和 ...

  10. Jquery选择器(三)

    过滤选择器 4.属性过滤器 查找所有含有 id 属性的 div 元素$(document).ready(function(){ $("div[id]").css("col ...