传送门

半平面交。

首先,由显然成立法可以证明炸连续的几个总比分散火力效果更佳。

所以二分答案,转化为判定问题,即间隔$ans$个点的连线的半平面交是否为空。

半平面交判定即可。

时间复杂度:$O(Nlog^2N)$

  1. //UVaLive4992
  2. //by Cydiater
  3. //2017.2.1
  4. #include <iostream>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <string>
  8. #include <cmath>
  9. #include <ctime>
  10. #include <cstdlib>
  11. #include <queue>
  12. #include <map>
  13. #include <algorithm>
  14. #include <iomanip>
  15. #include <bitset>
  16. #include <set>
  17. #include <vector>
  18. using namespace std;
  19. #define ll long long
  20. #define up(i,j,n) for(int i=j;i<=n;i++)
  21. #define down(i,j,n) for(int i=j;i>=n;i--)
  22. #define cmax(a,b) a=max(a,b)
  23. #define cmin(a,b) a=min(a,b)
  24. #define db double
  25. #define Vector Point
  26. const int MAXN=1e5+5;
  27. const int oo=0x3f3f3f3f;
  28. const db eps=1e-10;
  29. inline int read(){
  30. char ch=getchar();int x=0,f=1;
  31. while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
  32. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  33. return x*f;
  34. }
  35. int dcmp(db x){if(fabs(x)<eps)return 0;else return x<0?-1:1;}
  36. struct Point{
  37. db x,y;
  38. Point(db x=0,db y=0):x(x),y(y){}
  39. };
  40. Vector operator + (Point x,Point y){return Vector(x.x+y.x,x.y+y.y);}
  41. Vector operator - (Point x,Point y){return Vector(x.x-y.x,x.y-y.y);}
  42. Vector operator * (Vector x,db p){return Vector(x.x*p,x.y*p);}
  43. Vector operator / (Vector x,db p){return Vector(x.x/p,x.y/p);}
  44. bool operator < (const Vector &x,const Vector &y){return dcmp(x.x-y.x)==0?x.y<y.y:x.x<y.x;}
  45. bool operator == (const Vector &x,const Vector &y){return dcmp(x.x-y.x)==0&&dcmp(x.y-y.y)==0;}
  46. struct Line{
  47. Point P;
  48. Vector v;
  49. db ang;
  50. Line(){}
  51. Line(Point P,Vector v):P(P),v(v){ang=atan2(v.y,v.x);}
  52. };
  53. bool operator < (const Line &x,const Line &y){return x.ang<y.ang;}
  54. Point V[MAXN],P[MAXN];
  55. int N,top,head,tail;
  56. Line L[MAXN],q[MAXN];
  57. namespace solution{
  58. Point Write(){db x=read(),y=read();return Point(x,y);}
  59. db Cross(Vector x,Vector y){return x.x*y.y-x.y*y.x;}
  60. bool Onleft(Point P,Line Li){return dcmp(Cross(P-Li.P,Li.v))<0;}
  61. void Prepare(){
  62. V[0]=Write();
  63. down(i,N-1,1)V[i]=Write();
  64. }
  65. void Modify(int siz){
  66. up(i,0,N-1)L[i]=Line(V[i],V[(i+siz)%N]-V[i]);
  67. }
  68. Point LineMeet(Line x,Line y){
  69. db t=Cross(y.v,x.P-y.P)/Cross(x.v,y.v);
  70. return x.P+x.v*t;
  71. }
  72. bool check(){
  73. head=1;tail=0;q[++tail]=L[0];
  74. up(i,1,N-1){
  75. while(head<tail&&!Onleft(P[tail-1],L[i]))tail--;
  76. while(head<tail&&!Onleft(P[head],L[i]))head++;
  77. q[++tail]=L[i];
  78. if(dcmp(q[tail-1].ang-q[tail].ang)==0){
  79. tail--;
  80. if(Onleft(L[i].P,q[tail]))q[tail]=L[i];
  81. }
  82. if(head<tail)P[tail-1]=LineMeet(q[tail-1],q[tail]);
  83. }
  84. while(head<tail&&!Onleft(P[tail-1],q[head]))tail--;
  85. return tail-head>1;
  86. }
  87. void Solve(){
  88. int leftt=0,rightt=N-1,mid;
  89. while(leftt+1<rightt){
  90. mid=(leftt+rightt)>>1;
  91. Modify(mid);
  92. if(check()) leftt=mid;
  93. else rightt=mid;
  94. }
  95. Modify(rightt);
  96. if(check()) cout<<rightt<<endl;
  97. else cout<<leftt<<endl;
  98. }
  99. }
  100. int main(){
  101. //freopen("input.in","r",stdin);
  102. using namespace solution;
  103. while(scanf("%d",&N)!=EOF){
  104. Prepare();
  105. Solve();
  106. }
  107. return 0;
  108. }

UVaLive4992:Jungle Outpost的更多相关文章

  1. LA 4992 Jungle Outpost(半平面交)

    Jungle Outpost [题目链接]Jungle Outpost [题目类型]半平面交 &题解: 蓝书282 我自己写的代码居然AC了!!! 刘汝佳的说要right要-3什么的,还要特判 ...

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

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

  3. 【二分】【半平面交】Gym - 101309J - Jungle Outpost

    发现炸毁的瞭望塔必然是连续的,其余下的部分是一个半平面. 二分答案,枚举所有可能的炸毁情况,做个半平面交,如果交出来面积是0,就可以保证不存在安全区域. #include<cstdio> ...

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

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

  5. uvalive 4992 Jungle Outpost

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

  6. uva 1475 - Jungle Outpost

    半平面交,二分: 注意,题目的点是顺时针给出的: #include<cstdio> #include<algorithm> #include<cmath> #def ...

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

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

  8. bzoj千题计划210:bzoj2642 | Poj3968 | UVALive 4992| hdu 3761 Jungle Outpost

    http://www.lydsy.com/JudgeOnline/problem.php?id=2642 题意: n个瞭望台,形成一个凸n边形.这些瞭望台的保护范围是这个凸包内的任意点. 敌人进攻时, ...

  9. [GodLove]Wine93 Tarining Round #10

    比赛链接: http://www.bnuoj.com/v3/contest_show.php?cid=4159 题目来源: lrj训练指南---几何算法 Flag ID Title   A Board ...

随机推荐

  1. cocos2dx游戏--欢欢英雄传说--添加攻击按钮

    接下来添加攻击按钮用于执行攻击动作.同时修复了上一版移动时的bug.修复后的Player::walkTo()函数: void Player::walkTo(Vec2 dest) { if (_seq) ...

  2. 在腾讯云服务器上体验Docker

    版权声明:本文由姚俊刚原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/85 来源:腾云阁 https://www.qclou ...

  3. SNMP信息泄露漏洞

    SNMP协议简介 名称:SNMP(Simple Network Management Protocol)简单网络管理协议 端口:161 协议:UDP 用途:SNMP代理者以变量呈现管理资料.管理系统透 ...

  4. mysql 效率 inner join 与 where in

    -- report 123.77k行 report_loss 620 行 -- inner join ;report_loss 索引 all report 索引 eq_ref ; -- total 0 ...

  5. javascript飞机大战-----009游戏结束

    /* 游戏引擎 */ var Engine = { //刚开始的游戏状态 gameStatus:false, //所以敌机 enemy:{}, //子弹 bullet:{}, //得分 scroe:0 ...

  6. Android N 通知概览及example

    概述 Android App的通知在维护你的App和用户之间的交互起着举足轻重的作用,为了提供更好的用户体验,Android N上的通知提供了可视化刷新,自定义视图和直接回复等功能.另外还提出了Mes ...

  7. Spring boot官方文档学习(一)

    个人说明:本文内容都是从为知笔记上复制过来的,样式难免走样,以后再修改吧.另外,本文可以看作官方文档的选择性的翻译(大部分),以及个人使用经验及问题. 其他说明:如果对Spring Boot没有概念, ...

  8. 原!上线遇到的问题, java序列化关键字transient 修饰的属性变成null了

    1.问题描述: 某个功能点,user对象 放入session,后再另外地方取出,结果某个字段没有了.再本地和测试环境都是ok的,但是线上环境就是不行. 后来看到这个user对象的那个属性是加了tran ...

  9. Ultra-QuickSort---poj2299 (归并排序.逆序数.树状数组.离散化)

    题目链接:http://poj.org/problem?id=2299 题意就是求把数组按从小到大的顺序排列,每次只能交换相邻的两个数, 求至少交换了几次 就是求逆序数 #include<std ...

  10. Python开发【Tornado】:异步Web服务(二)

    真正的 Tornado 异步非阻塞 前言: 其中 Tornado 的定义是 Web 框架和异步网络库,其中他具备有异步非阻塞能力,能解决他两个框架请求阻塞的问题,在需要并发能力时候就应该使用 Torn ...