Jungle Outpost

【题目链接】Jungle Outpost

【题目类型】半平面交

&题解:

蓝书282 我自己写的代码居然AC了!!!

刘汝佳的说要right要-3什么的,还要特判3,我感觉就不需要,所以我就没写,交了一发,想着应会wa吧,结果居然tmA了!!!

&代码:

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; struct Point {
double x, y;
Point(double x = 0, double y = 0): x(x), y(y) {}
};
typedef Point Vector; Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x * p, A.y * p); }
bool operator < (Point a, Point b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
double Cross(Vector A, Vector B) { return A.x * B.y - A.y * B.x; } double PolygonArea(vector<Point> p) {
int n = p.size();
double ans = 0;
for(int i = 1; i < n - 1; i++) {
ans += Cross(p[i] - p[0], p[i + 1] - p[0]);
}
return ans / 2;
} struct Line {
Point p, v;
double ang;
Line() {}
Line(Point p, Vector v): p(p), v(v) { ang = atan2(v.y, v.x); }
bool operator <(const Line& l) const {
return ang < l.ang;
}
}; const double eps = 1e-9; bool OnLeft(Line l, Point p) {
//bug 是p-l.p 不是l.p-p
return Cross(l.v, p - l.p) > 0;
}
Point LineInter(Line a, Line b) {
Vector u = a.p - b.p;
double t = Cross(b.v, u) / Cross(a.v, b.v);
return a.p + a.v * t;
} vector<Point> HalfplaneIntersection(vector<Line> L) {
int n = L.size();
sort(L.begin(), L.end());
int first, last;
vector<Point> p(n), ans;
vector<Line> que(n);
que[first = last = 0] = L[0];
for(int i = 1; i < n; i++) {
while(first < last && !OnLeft(L[i], p[last - 1])) last--;
while(first < last && !OnLeft(L[i], p[first])) first++;
que[++last] = L[i];
if(fabs(Cross(que[last].v, que[last - 1].v)) < eps) {
last--;
if(OnLeft(que[last], L[i].p)) que[last] = L[i];
}
if(first < last) p[last - 1] = LineInter(que[last], que[last - 1]);
}
while(first < last && !OnLeft(que[first], p[last - 1])) last--;
if(last - first <= 1) return ans;
p[last] = LineInter(que[first], que[last]);
for(int i = first; i <= last; i++) {
ans.push_back(p[i]);
}
return ans;
} int main() {
//("E:1.in", "r", stdin);
int n;
while(~scanf("%d", &n)) {
vector<Point> p;
int x, y;
for(int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
p.push_back(Point(x, y));
}
reverse(p.begin(), p.end());
int left = 0, right = n;
while(left <= right) {
int mid = left + right >> 1;
vector<Line> L;
for(int i = 0; i < n; i++) {
L.push_back(Line(p[i], p[(i + mid + 1) % n] - p[i]));
}
vector<Point> pp = HalfplaneIntersection(L);
if(pp.empty()) right = mid - 1;
else left = mid + 1;
// printf("%d %d %d \n", left, mid, right);
}
//这要输出了答案是left 跟right没有关系
printf("%d\n", left);
// printf("%d\n", right);
}
return 0;
}

LA 4992 Jungle Outpost(半平面交)的更多相关文章

  1. UVALive 4992 Jungle Outpost(半平面交判存)

    Jungle Outpost Time limit: 15.000 seconds Description There is a military base lost deep in the jung ...

  2. UVALive 4992 Jungle Outpost(半平面交)

    题意:给你n个塔(点)形成一个顺时针的凸包,敌人可以摧毁任何塔,摧毁后剩下的塔再组成凸包 在开始的凸包内选一点为主塔,保证敌人摧毁尽量多塔时主塔都还在现在的凸包内,求出最多摧毁的塔 题解:这题关键就是 ...

  3. uvalive 4992 Jungle Outpost

    题意:一个凸边型,目标在凸边型内且最优.问最多删除几个点使目标暴露在新凸边型外面. 思路:二分+半平面相交. #include<cstdio> #include<cmath> ...

  4. UVa 1475 (二分+半平面交) Jungle Outpost

    题意: 有n个瞭望塔构成一个凸n边形,敌人会炸毁一些瞭望台,剩下的瞭望台构成新的凸包.在凸多边形内部选择一个点作为总部,使得敌人需要炸毁的瞭望塔最多才能使总部暴露出来.输出敌人需要炸毁的数目. 分析: ...

  5. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  6. LA 2218 (半平面交) Triathlon

    题意: 有n个选手,铁人三项有连续的三段,对于每段场地选手i分别以vi, ui 和 wi匀速通过. 对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列). 分析: 粗一看,这不像一道计 ...

  7. LA 3890 (半平面交) Most Distant Point from the Sea

    题意: 给出一个凸n边形,求多边形内部一点使得该点到边的最小距离最大. 分析: 最小值最大可以用二分. 多边形每条边的左边是一个半平面,将这n个半平面向左移动距离x,则将这个凸多边形缩小了.如果这n个 ...

  8. LA 2218 Triathlon(半平面交)

    Triathlon [题目链接]Triathlon [题目类型]半平面交 &题解: 做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空. 还有刘汝佳的代码总是写const +& ...

  9. LA 3890 Most Distant Point from the Sea(半平面交)

    Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...

随机推荐

  1. let 与 const 的用法

    let 与 const 的用法 let 用来声明变量,并且会在当前作用域形成 代码块 conts 用来声明常量,所谓常量就是物理指针不可以更改的变量. 所谓代码块,最简单的做法就是(这个 {} 就是一 ...

  2. 【每日一题】 UVA - 213 Message Decoding 模拟解码+读入函数+阅读题

    题意:阅读理解难度一道比一道难orz.手摸了好久样例 题解: 读入:大循环用getline读入header顺便处理一下,  里面再写两重循环,外层一次读三个串,内层一次读num个串. 之后就查表,线性 ...

  3. Sethi model

    小结: 1. 销量 广告 微分方程 动态系统 市场份额 https://en.wikipedia.org/wiki/Sethi_model The Sethi model was developed ...

  4. Chap1:基本概念[《区块链中文词典》维京&甲子]

  5. linux测试环境维护之磁盘空间维护

    常见需要定期清理的日志有: 清理oracle监听日志: 1.进入/opt/oracle/db/diag/tnslsnr/sels-186/listener/alert目录下, 执行命令: rm -rf ...

  6. 新兴的API(fileReader、geolocation、web计时、web worker)

    requestAnimationFrame() 每次浏览器重绘之前会调用这个方法!!! 它接收一个参数,就是回调函数: 它可以保证在最佳的间隔时间调用传入的回调函数,以达到让屏幕产生最流畅的动画效果. ...

  7. webpack4入门配置

    下面是抄过来的,方便自己翻越 webpack4.x入门配置   1.首先npm install webpack webpack-cli webpack-dev-server -g (mac电脑用超级管 ...

  8. java 随机抽取案例,不重复抽取

    以学生类为例,先准备一个Student类 package cn.sasa.demo1; public class Student { private int id; private String na ...

  9. js模拟下拉框

    html <label class="selectGroup"> <span class="selectP"></span> ...

  10. 在Ubuntu上实现局域网共享文件夹

    在Ubuntu上实现局域网共享文件夹如果你的系统是Ubuntu 14.04.14.10或12.04,有两个方法可以使你通过局域网在搭载Windows或其他Linux的电脑上共享本地文件.对局域网中的每 ...