题意:判断一堆小点有多少个在任意三个大点构成的三角形里面。

思路:其实就是判断点在不在凸包里面,判断的话可以使用二分来判断,就是判断该点在凸包的哪两个点和起点的连线之间。

代码:

 /** @xigua */
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
#include<queue>
#include<set>
#include<string>
#include<map>
#include<climits>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 5e4 + ;
const int mod = ( << ) - ;
const int INF = 1e8 + ;
const ll inf = 1e15 + ;
const db eps = 1e-; struct Node {
ll x, y, id;
} po[maxn];
int n;
int flag; bool cmp(const Node &a, const Node &b) {
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
} ll mul(ll x1, ll x2, ll y1, ll y2) {
return x1 * y2 - x2 * y1;
}
Node S[maxn];
int top; void ch(Node cur) {
while (top > flag) {
Node po1 = S[top];
Node po2 = S[top-];
ll x1 = po1.x - po2.x, y1 = po1.y - po2.y;
ll x2 = cur.x - po2.x, y2 = cur.y - po2.y;
if (mul(x1, x2, y1, y2) >= ) {
top--;
}
else break;
}
S[++top] = cur;
} int ok(int mid, ll x, ll y) {
ll x1 = S[mid].x - S[].x, y1 = S[mid].y - S[].y;
ll x2 = x - S[].x, y2 = y - S[].y;
ll tmp = mul(x1, x2, y1, y2);
if (tmp > ) return ;
if (tmp == ) return ;
return ;
} void solve() {
while (cin >> n) {
for (int i = ; i <= n; i++) {
scanf("%I64d%I64d", &po[i].x, &po[i].y);
po[i].id = i;
}
sort(po+, po++n, cmp);
top = ;
flag = ;
for (int i = ; i <= n; i++) {
ch(po[i]);
}
flag = top;
for (int i = n-; i >= ; i--) {
ch(po[i]);
}
top--;
int q, ans = ; cin >> q;
Node tmp[maxn];
for (int i = ; i <= top; i++)
tmp[i] = S[i];
for (int i = ; i <= top; i++)
S[i] = tmp[top-i+];
while (q--) {
ll x, y;
scanf("%I64d%I64d", &x, &y);
int l = , r = top; //二分上界和下界
while (l < r) {
int mid = l + r + >> ;
if (ok(mid, x, y)) //在当前这条线之上
l = mid;
else r = mid - ;
}
if (l == top) { //在上界需要特殊判断
if (ok(l, x, y) == ) {
ll a = x - S[].x, b = y - S[].y;
ll dis1 = a * a + b * b;
a = S[l].x - S[].x, b = S[l].y - S[].y;
ll dis2 = a * a + b * b;
if (dis1 <= dis2) ans++;
}
continue;
}
Node xx[];
xx[] = S[], xx[] = S[l], xx[] = S[l+], xx[] = S[];
ll are1 = ;
for (int i = ; i <= ; i++) {
ll x1 = xx[i].x - x, y1 = xx[i].y - y;
ll x2 = xx[i+].x - x, y2 = xx[i+].y - y;
ll tmp = mul(x1, x2, y1, y2);
if (tmp < ) tmp = -tmp;
are1 += tmp;
}
ll x1 = xx[].x - xx[].x, y1 = xx[].y - xx[].y;
ll x2 = xx[].x - xx[].x, y2 = xx[].y - xx[].y;
ll are2 = mul(x1, x2, y1, y2);
//if (are1 < 0) are1 = -are1;
if (are2 < ) are2 = -are2;
if (are2 == are1) ans++; //通过面积来判断,are1代表的是加上该点的
}
cout << ans << endl;
}
} int main() {
//cin.sync_with_stdio(false);
//freopen("in.txt", "r", stdin);
//freopen("isharp.out", "w", stdout);
int t = ; //cin >> t; while (t--) {
solve();
}
return ;
}

Gym 100883J palprime(二分判断点在凸包里)的更多相关文章

  1. Gym 101128J Saint John Festival(凸包 + 二分判点和凸包关系)题解

    题意:给你一堆黑点一堆红点,问你有最多几个黑点能找到三个红点,使这个黑点在三角形内? 思路:显然红点组成的凸包内的所有黑点都能做到.但是判断黑点和凸包的关系朴素方法使O(n^2),显然超时.那么我现在 ...

  2. A Round Peg in a Ground Hole(判断是否是凸包,点是否在凸包内,圆与多边形的关系)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4628   Accepted: 1434 Description The D ...

  3. POJ_2318_TOYS&&POJ_2398_Toy Storage_二分+判断直线和点的位置关系

    POJ_2318_TOYS&&POJ_2398_Toy Storage_二分+判断直线和点的位置 Description Calculate the number of toys th ...

  4. UVALive7461 - Separating Pebbles 判断两个凸包相交

    //UVALive7461 - Separating Pebbles 判断两个凸包相交 #include <bits/stdc++.h> using namespace std; #def ...

  5. php判断检测一个数组里有没有重复的值

    php判断检测一个数组里有没有重复的值 php里有一个处理数组重复值得函数array_unique,我们的思路就是用这个函数来实现的. if (count($array) != count(array ...

  6. BZOJ-2756 奇怪的游戏 黑白染色+最大流+当前弧优化+二分判断+分类讨论

    这个题的数据,太卡了,TLE了两晚上,各种调试优化,各种蛋疼. 2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MB Submit ...

  7. UVa 10256 (判断两个凸包相离) The Great Divide

    题意: 给出n个红点,m个蓝点.问是否存在一条直线使得红点和蓝点分别分布在直线的两侧,这些点不能再直线上. 分析: 求出两种点的凸包,如果两个凸包相离的话,则存在这样一条直线. 判断凸包相离需要判断这 ...

  8. codeforces 8D Two Friends 二分+ 判断三个圆是否有公共交点

    题目链接 有两个人x, y, 现在在A点, x要直接去B点, y要先去C点在去B点, 现在给出x, y两人可以行走的最大距离T1, T2, 求出他们从A点出发之后, 可以走的最长的公共路径. 我们先看 ...

  9. K - Video Reviews Gym - 101755K (二分)

    题目链接: K - Video Reviews Gym - 101755K 题目大意: 一家公司想让个人给他们的产品评论,所以依次去找这个人,第i个人会评论当且仅当已经有个人评论或他确实对这个产品感兴 ...

随机推荐

  1. Python使用Timer实现验证码功能

    from threading import Timer import random class Code: def __init__(self): self.make_cache() def make ...

  2. Subresource Integrity(子资源一致性)和JS DDos 攻击

    以下文章转载自 http://www.cnblogs.com/zoucaitou/p/4505483.html 和 http://www.puronglong.com/blog//2015/04/12 ...

  3. 洛谷 - UVA11346 - 概率 Probability - 积分

    要是没学过高等数学的积分怎么办呢?可以求助于自适应辛普森法. 容易发现其实这个图形是对称的,我们只要求第一象限就可以了,第一象限如上图. 由于取点是在面积内等概率的,由高中的几何概型可知,所求概率为: ...

  4. github新手使用

    1.首先要先在github的官网注册一个属于自己的账号.https://github.com/ 2.注册完成后需要一些简单的设置,先创建一个属于自己的仓库,repository 3.创建仓库 4.如何 ...

  5. 我不知道的C#—字符串池机制

    字符串具有值类型的特点对字符串,对同一个字符串大量修改或者对多个引用赋值同一个字符串对象时会产生大量的临时字符串对象,影响性能,但是CLR为我们做了一些工作来消除这些弊端.      对同一个字符串大 ...

  6. 3DMAX 1快捷键及常用操作

    开启,关闭快捷键 ,使用快捷键时要按下这个按钮 快捷键查看与修改 自定义-自定义用户界面(cutomize user interface):设置和查看快捷键 位置变换 Z: 复位---物体被移动飞了的 ...

  7. [Xcode 实际操作]二、视图与手势-(5)给图像视图添加圆角效果

    目录:[Swift]Xcode实际操作 本文将演示给矩形图片添加圆角效果 import UIKit class ViewController: UIViewController { override ...

  8. Proteomes of paired human cerebrospinal fluid and plasma: Relation to blood-brain barrier permeability in older adults (文献分享一组-潘火珍)

    题目:Proteomes of paired human cerebrospinal fluid and plasma: Relation to blood-brain barrier permeab ...

  9. 字符串匹配,KMP算法

    KMP的详解见:https://segmentfault.com/a/1190000008575379 主要难点在于Next数组的理解,KMP是不需要回溯的匹配算法. #include<iost ...

  10. UVa12304(计算几何中圆的基本操作)

    断断续续写了250多行的模拟,其间被其他事情打扰,总共花了一天才AC吧~ 这道题目再次让我明白,有些事情看起来很难,实际上并没有我们想象中的那么难.当然了我主要指的不是这个题的难度…… 也是初学计算几 ...