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. 存储json数据的编码问题

    在使用json.dumps时要注意一个问题   >>> import json >>> print json.dumps('中国') "\u4e2d\u5 ...

  2. 【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题

    https://cn.vjudge.net/problem/UVA-1368 二维的hamming距离算法: For binary strings a and b the Hamming distan ...

  3. MySQL异步复制-加强版

    准备:主备库版本一致,主从库正常安装软件. 1.主库上设置一个复制使用的账户: mysql> grant replication slave,replicate client on *.* to ...

  4. Monkey简介及环境搭建(1)

    简介:Monkey是Android SDK自带的测试工具,是一个命令行工具,可以运行在模拟器中或者实际设备中,它向系统发送伪随机的用户事件流(如按键输入,触摸屏输入,手势输入等),实现对正在开发的应用 ...

  5. mysql分库 分表

    原文链接:http://www.jianshu.com/p/89311703b320 传统的分库分表传统的分库分表都是通过应用层逻辑实现的,对于数据库层面来说,都是普通的表和库.分库分库的原因 首先, ...

  6. Python开发【模块】:aiohttp(二)

    AIOHTTP 1.文件上传 ① 单个文件上传 服务端 async def post(self, request): reader = await request.multipart() # /!\ ...

  7. state访问状态对象

    状态对象赋值给内部对象,也就是把stroe.js中的值,赋值给我们模板里data中的值.我们有三种赋值方式: 1.通过computed的计算属性直接赋值 Count.vue {count} <s ...

  8. bat删除过期文件(FORFILES)

    关键词:bat删除过期文件,bat,FORFILES 原文:https://blog.csdn.net/sandy9919/article/details/82932460 --最佳实践 :: IIS ...

  9. 晨枫U盘启动盘制作工具V4.0-安装原版Win7

    第一类方法(32位64位系统通用): [1]找到Windows7系统的iso镜像,用UltraISO或者WinRAR打开iso镜像,然后提取/解压所有文件到你的U盘根目录. [2]在你的U盘里找到名为 ...

  10. vue-router路由管理器

    安装vue-router npm install vue-router 在main.js中引入 import VueRouter from 'vue-router' Vue.use(VueRouter ...