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

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

代码:

 /** @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. mysql server安装(windows)

    1 在 https://dev.mysql.com/downloads/mysql/ 上下载mysql压缩包 2 解压,并把bin目录加入环境变量 3 初始化,完成后会在mysql根目录下生成data ...

  2. 【转】Visual Studio 选择相同变量高亮

    转:http://www.cnblogs.com/stone_w/p/3613760.html 前段时间一直在使用matlab,今天需要使用vs2008,而用惯了matlab,习惯了其中一项选中变量高 ...

  3. .NET Core 3.0之深入源码理解Configuration(三)

      写在前面 上一篇文章讨论了文件型配置的基本内容,本篇内容讨论JSON型配置的实现方式,理解了这一种配置类型的实现方式,那么其他类型的配置实现方式基本可以触类旁通.看过了上一篇文章的朋友,应该看得出 ...

  4. Chrome开发者工具 debug 调试

    Chrome 的开发者工具分为 8 个大模块,每个模块及其主要功能为: Element 标签页: 用于查看和编辑当前页面中的 HTML 和 CSS 元素. Network 标签页:用于查看 HTTP ...

  5. lightoj 1096【矩阵快速幂(作为以后的模板)】

    基础矩阵快速幂何必看题解 #include <bits/stdc++.h> using namespace std; /* 0 1 2 3 4 5 6 7 0 0 0 */ const i ...

  6. UGUI DOTween渐隐渐现

    Tween tweenAlpha; tweenAlpha = DOTween.To(() => MaskSpr.fillAmount, x => MaskSpr.fillAmount = ...

  7. IT兄弟连 JavaWeb教程 JSTL定义

    JSTL标签库实际上包含5个不同的标签库.JSTL1.1规范为这些标签库的URI和前缀做了预定,参见表7.3. 表3  JSTL标签库

  8. elasticsearch 备份和恢复

    curl   : http://keenwon.com/1393.html During snapshot initialization, information about all previous ...

  9. C# 可空类型(Nullable)

    C# 提供了一个特殊的数据类型,nullable 类型(可空类型),可空类型可以表示其基础值类型正常范围内的值,再加上一个 null 值. 例如,Nullable< Int32 >,读作& ...

  10. bryce1010专题训练——CDQ分治

    Bryce1010模板 CDQ分治 1.与普通分治的区别 普通分治中,每一个子问题只解决它本身(可以说是封闭的) 分治中,对于划分出来的两个子问题,前一个子问题用来解决后一个子问题而不是它本身 2.试 ...