Gym 101128J Saint John Festival(凸包 + 二分判点和凸包关系)题解
题意:给你一堆黑点一堆红点,问你有最多几个黑点能找到三个红点,使这个黑点在三角形内?
思路:显然红点组成的凸包内的所有黑点都能做到。但是判断黑点和凸包的关系朴素方法使O(n^2),显然超时。那么我现在有一个更好的方法判断点和凸包的关系。我固定一个红点,然后找连续两个红点使黑点 i 在这个三角形内(向量判),然后用二分查找是否存在这样的两个连续红点。这样复杂度为nlogn。
注意凸包不要用atan2的那种,会有精度误差...
代码:
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e4 + 10;
const int M = maxn * 30;
const ull seed = 131;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
struct point
{
double x,y;
}p[100000],a[100000],b[100000], g;
int n, tot;
bool cmp(point A,point B)
{
if(A.x!=B.x)
return A.x<B.x;
return A.y<B.y;
}
point operator -(point A,point B)
{
point c;
c.x=A.x-B.x;
c.y=A.y-B.y;
return c;
}
double cross(point A,point B)
{
return A.x*B.y-B.x*A.y;
}
void dopack()
{
tot=0;
for(int i=1;i<=n;i++)
{
while(tot>1&&cross(p[tot-1]-p[tot-2],a[i]-p[tot-2])<=0)tot--;
p[tot++]=a[i];
}
int k=tot;
for(int i=n-1;i>0;i--)
{
while(tot>k&&cross(p[tot-1]-p[tot-2],a[i]-p[tot-2])<=0)tot--;
p[tot++]=a[i];
}
if(n>1)tot--;
}
double turn(point st, point en, point q){
//正数:点在向量左侧
//负数:点在向量右侧
//0:点在向量直线上
return (st.x - q.x) * (en.y - q.y) - (en.x - q.x) * (st.y - q.y);
}
int mid(){
int l, r;
l = 1, r = tot - 2;
while(l <= r){
int m = (l + r) >> 1;
if(turn(p[0], p[m], g) >= 0 && turn(p[0], p[m + 1], g) <= 0){
if(turn(p[m], p[m + 1], g) >= 0) return 1;
return 0;
}
if(turn(p[0], p[m], g) >= 0){
l = m + 1;
}
else{
r = m - 1;
}
}
return 0;
}
int main(){
int m;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%lf%lf", &a[i].x, &a[i].y);
sort(a+1,a+1+n,cmp);
dopack();
// for(int i = 0; i < tot; i++){
// printf("* %lf %lf\n", p[i].x, p[i].y);
// }
scanf("%d", &m);
int ans = 0;
for(int i = 1; i <= m; i++){
scanf("%lf%lf", &g.x, &g.y);
ans += mid();
}
printf("%d\n", ans);
return 0;
}
Gym 101128J Saint John Festival(凸包 + 二分判点和凸包关系)题解的更多相关文章
- 【计算几何】【凸包】【极角排序】【二分】Gym - 101128J - Saint John Festival
平面上n个红点,m个黑点,问你多少个黑点至少在一个红三角形内. 对红点求凸包后,转化为询问有多少个黑点在凸包内. 点在凸多边形内部判定,选定一个凸包上的点作原点,对凸包三角剖分,将其他的点极角排序之后 ...
- Saint John Festival Gym - 101128J (凸包二分)
Problem J: Saint John Festival \[ Time Limit: 1 s \quad Memory Limit: 256 MiB \] 题意 给出\(n\)个大点,和\(m\ ...
- UVALive 7281 Saint John Festival (凸包+O(logn)判断点在凸多边形内)
Saint John Festival 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/J Description Porto's ...
- UVA - 13024 Saint John Festival 凸包+二分
题目链接:https://vjudge.net/problem/UVA-13024 题意:先给出\(L\)个点构造一个凸包,再给出\(S\)个点,询问有几个点在凸包内. 题解:判断点是否在凸包内的模板 ...
- UVA 13024: Saint John Festival(凸包+二分 ,判定多个点在凸包内)
题意:给定N个点,Q次询问,问当前点知否在N个点组成的凸包内. 思路:由于是凸包,我们可以利用二分求解. 二分思路1:求得上凸包和下凸包,那么两次二分,如果点在对应上凸包的下面,对应下凸包的上面,那么 ...
- 15-16 ICPC europe J Saint John Festival (graham扫描法+旋转卡壳)
题意:给n个大点,m个小点$(n<=1e5,m<=5e5),问有多少个小点,存在3个大点,使小点在三个大点组成的三角形内. 解题思路: 首先,易证,若该小点在某三大点行成的三角形内,则该小 ...
- 【bzoj3203】[Sdoi2013]保护出题人 凸包+二分
题目描述 输入 第一行两个空格隔开的正整数n和d,分别表示关数和相邻僵尸间的距离.接下来n行每行两个空格隔开的正整数,第i + 1行为Ai和 Xi,分别表示相比上一关在僵尸队列排头增加血量为Ai 点的 ...
- 【bzoj2402】陶陶的难题II 分数规划+树链剖分+线段树+STL-vector+凸包+二分
题目描述 输入 第一行包含一个正整数N,表示树中结点的个数.第二行包含N个正实数,第i个数表示xi (1<=xi<=10^5).第三行包含N个正实数,第i个数表示yi (1<=yi& ...
- 训练指南 UVA - 11090(最短路BellmanFord+ 二分判负环)
layout: post title: 训练指南 UVA - 11090(最短路BellmanFord+ 二分判负环) author: "luowentaoaa" catalog: ...
随机推荐
- [usaco2008 Oct]Pasture Walking 牧场旅行
题目描述 n个被自然地编号为1..n奶牛(1<=n<=1000)正在同样被方便的编号为1..n的n个牧场中吃草.更加自然而方便的是,第i个奶牛就在第i个牧场中吃草. 其中的一些对牧场被总共 ...
- 5V 升压 8.4V,5V 转 8.4V 做两节锂电池充电芯片
5V 升压 8.4V SOT23-6 封装的六脚升压 IC PW5300 是一颗 DC-DC 异步整流升压转换器芯片,输入电压范围 2.6V-5.5V.最高输出 电压 12V, PW5300 是一种电 ...
- flask文件下载
后端的代码 # coding:utf-8 from flask import Flask app = Flask(__name__) @app.route("/upload", m ...
- uni-app开发经验分享十八:对接第三方h5
1.uni-app中对接第三方为了防止跳出app使用了webview <template> <view> <web-view :src="url" @ ...
- Py数据类型—列表,字典,元组
列表:数据类型list. 写法li=[1,12,9,"sdsad",["ad","dd"] ].用中括号括起来,用逗号分割每个元素列表中元素 ...
- MySQL 中的临时表
在使用 explain 解析一个 sql 时,有时我们会发现在 extra 列上显示 using temporary ,这表示这条语句用到了临时表,那么临时表究竟是什么?它又会对 sql 的性能产生什 ...
- Angular入门到精通系列教程(14)- Angular 编译打包 & Docker发布
目录 1. 概要 2. 编译打包 2.1. 基本打包命令 2.2. 打包部署到二级目录 3. Angular站点的发布 3.1. web服务器发布 3.2. 使用docker发布 4. 总结 环境: ...
- js中的事件委托(事件代理)详解
本文转载:https://www.cnblogs.com/liugang-vip/p/5616484.html#!comments js中的事件冒泡.事件委托是js 中一些需要注意的小知识点,这里结合 ...
- all header field names in both HTTP requests and HTTP responses are case-insensitive.
https://tools.ietf.org/html/rfc6455#section-4.2.1 Please note that according to [RFC2616], all heade ...
- 腾讯libco协程原理
https://blog.csdn.net/GreyBtfly/article/details/83688420 堆栈 https://blog.csdn.net/lqt641/article/det ...