题意

PDF

分析

炸连续的比炸单独的好。

二分答案,每种炸连续的构成一些半平面,判断半平面交是否为空。

时间复杂度\(O(T n \log^2)\)

代码

这题卡常,排序的时候必须事先算出幅角,不然会TLE。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
    rg T data=0;
    rg int w=1;
    rg char ch=getchar();
    while(!isdigit(ch))
    {
        if(ch=='-')
            w=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        data=data*10+ch-'0';
        ch=getchar();
    }
    return data*w;
}
template<class T>T read(T&x)
{
    return x=read<T>();
}
using namespace std;
typedef long long ll;

struct Point
{
    double x,y;

    Point(double x=0,double y=0)
    :x(x),y(y){}
};
typedef Point Vector;

Vector operator+(co Vector&A,co Vector&B)
{
    return Vector(A.x+B.x,A.y+B.y);
}

Vector operator-(co Vector&A,co Vector&B)
{
    return Vector(A.x-B.x,A.y-B.y);
}

Vector operator*(co Vector&A,double p)
{
    return Vector(A.x*p,A.y*p);
}

double Dot(co Vector&A,co Vector&B)
{
    return A.x*B.x+A.y*B.y;
}

double Cross(co Vector&A,co Vector&B)
{
    return A.x*B.y-A.y*B.x;
}

double Length(co Vector&A)
{
    return sqrt(Dot(A,A));
}

Vector Normal(co Vector&A)
{
    double L=Length(A);
    return Vector(-A.y/L,A.x/L);
}

double PolygonArea(vector<Point>p)
{
    int n=p.size();
    double area=0;
    for(int i=1;i<n-1;++i)
        area+=Cross(p[i]-p[0],p[i+1]-p[0]);
    return area/2;
}

struct Line
{
    Point P;
    Vector v;
    double ang;

    Line(Point P=0,Vector v=0)
    :P(P),v(v){ang=atan2(v.y,v.x);}

    bool operator<(co Line&L)co
    {
        return ang<L.ang;
    }
};

bool OnLeft(co Line&L,co Point&p)
{
    return Cross(L.v,p-L.P)>0;
}

Point LineLineIntersection(co Line&a,co 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;
}

co double eps=1e-6;

vector<Point>HalfplaneIntersection(vector<Line>&L)
{
    int n=L.size();
    sort(L.begin(),L.end());

    int first,last;
    vector<Point>p(n);
    vector<Line>q(n);
    vector<Point>ans;

    q[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;
        q[++last]=L[i];
        if(fabs(Cross(q[last].v,q[last-1].v))<eps)
        {
            --last;
            if(OnLeft(q[last],L[i].P))
                q[last]=L[i];
        }
        if(first<last)
            p[last-1]=LineLineIntersection(q[last-1],q[last]);
    }
    while(first<last&&!OnLeft(q[first],p[last-1]))
        --last;
    if(last-first<=1)
        return ans;
    p[last]=LineLineIntersection(q[last],q[first]);

    for(int i=first;i<=last;++i)
        ans.push_back(p[i]);
    return ans;
}

co int N=5e4;
int n;
Point P[N];

bool check(int m)
{
    vector<Line>lines;
    for(int i=0;i<n;++i)
        lines.push_back(Line(P[(i+m+1)%n],P[i]-P[(i+m+1)%n]));
    return HalfplaneIntersection(lines).empty();
}

int solve()
{
    if(n==3)
        return 1;
    int L=1,R=n-3,res;
    while(L<=R)
    {
        int M=(L+R)>>1;
        if(check(M))
            res=M,R=M-1;
        else
            L=M+1;
    }
    return res;
}

int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;++i)
        {
            read(P[i].x);read(P[i].y);
        }
        printf("%d\n",solve());
    }
    return 0;
}

LA4992 Jungle Post的更多相关文章

  1. poj 1251 Jungle Roads (最小生成树)

    poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...

  2. Jungle Roads[HDU1301]

    Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  3. Jungle Roads

    Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid ...

  4. POJ 1251 Jungle Roads (prim)

    D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su ...

  5. hdu 1301 Jungle Roads 最小生成树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...

  6. POJ 1251 && HDU 1301 Jungle Roads (最小生成树)

    Jungle Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/A http://acm.hust.edu.cn/vju ...

  7. kruskal算法求最小生成树(jungle roads的kruskal解法)

    注意: 注意数组越界问题(提交出现runtimeError代表数组越界) 刚开始提交的时候,边集中边的数目和点集中点的数目用的同一个宏定义,但是宏定义是按照点的最大数定义的,所以提交的时候出现了数组越 ...

  8. 最小生成树Jungle Roads

    这道题一定要注意录入方式,我用的解法是prime算法 因为单个字符的录入会涉及到缓冲区遗留的空格问题,我原本是采用c语言的输入方法录入数据的,结果对了,但是提交却一直wrong,后来改成了c++的ci ...

  9. POJ1251 Jungle Roads 【最小生成树Prim】

    Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19536   Accepted: 8970 Des ...

随机推荐

  1. linux根分区满了如何处理,查找大文件方法

    一:如果linux根分区使用量达到100%,会造成如下现象: root不能登录 系统不能正常启动 二:通过命令查找根分区内的大文件 du -sh /* 2>/dev/null | sort -h ...

  2. jvm-垃圾收集器与内存分配策略

    垃圾收集器与内存分配策略 参考: https://my.oschina.net/hosee/blog/644085 http://www.cnblogs.com/zhguang/p/Java-JVM- ...

  3. how to get a controller instance in another controller

    https://stackoverflow.com/questions/16870413/how-to-call-another-controller-action-from-a-controller ...

  4. 如何理解Hibernate的延迟加载机制?在实际应用中,延迟加载与Session关闭的矛盾是如何处理的?

    延迟加载就是并不是在读取的时候就把数据加载进来,而是等到使用时再加载.Hibernate使用了虚拟代理机制实现延迟加载,我们使用Session的load()方法加载数据或者一对多关联映射在使用延迟加载 ...

  5. springBean参数注入的几个方法

    1.普通方式注入 applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> < ...

  6. mysql官网下载链接——绿色版&安装版

    windows64位5.5.60安装版 https://downloads.mysql.com/archives/get/file/mysql-5.5.60-winx64.msi windows64位 ...

  7. RabbitMQ初体验

    这里官方使用的Pom是4.0.2版本 <dependencies> <dependency> <groupId>com.rabbitmq</groupId&g ...

  8. TF卡.之前的(20180923)

    1.京东上搜到的(购买记录) ZC:64G的应该是 只买了一个 另一个取消了 2.TB上搜到的 购买记录是这样的(注意 也有 取消的) 3. 4. 5.

  9. 自己用java实现飞鸽传书 1 - 实现socket通信

    第一步: 建立服务端客户端,实现端到端通信.因为要传递文件,信号量较大,故使用TCP/IP协议. 服务端和客户端都要建立socket,而后通过socket进行通信.目前只实现服务端到客户端的单向通信. ...

  10. 门户diy实现翻页功能的方法

    1.打开 \source\class\block\portal\block_article.php 文件 找到 function getdata($style, $parameter) 修改为 fun ...