题目链接

求平面最大点对。

找凸包 -> 根据凸包运用旋转卡壳算法求最大点对(套用kuang巨模板)

关于旋转卡壳算法

#include<bits/stdc++.h>
using namespace std;

struct point
{
    int x,y;
    point operator -(const point& rhs)const
    {
        point ret;
        ret.x=x-rhs.x;
        ret.y=y-rhs.y;
        return ret;
    }
    int operator *(const point& rhs)const//叉乘
    {
        return x*rhs.y-y*rhs.x;
    }
    bool operator <(const point& rhs)const
    {
        return x<rhs.x||x==rhs.x&&y<rhs.y;
    }
} p[],s[];
int top;

bool ok(point A,point B,point C)    //判断ABC是否是按逆时针顺序给出
{
    ;
}
int dist2(point a,point b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int rotating_calipers()
{
    ;
    point v;
    ;
    ; i < top; i++)
    {
        v = s[i]-s[(i+)%top];
        )%top]-s[cur])) < )
            cur = (cur+)%top;
        ret = max(ret,max(dist2(s[i],s[cur]),dist2(s[(i+)%top],s[(cur+)%top])));
    }
    return ret;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        ; i<n; i++)
            scanf("%d%d",&p[i].x,&p[i].y);

        sort(p,p+n);
        top=;
        ; i<n; i++)  //求下凸包
        {
             && !ok(s[top-],s[top-],p[i]))
                top--;
            s[top++]=p[i];
        }
        ;
        ; i>=; i--)  //求上凸包
        {
             && !ok(s[top-],s[top-],p[i]))
                top--;
            s[top++]=p[i];
        }
        --top;    //    首尾点相同,故舍去
        int ans=rotating_calipers();
        printf("%d\n",ans);
    }
}

最新文章

  1. SignalR + KnockoutJS + ASP.NET MVC4 实现井字游戏
  2. POJ 1947 (树形DP+背包)
  3. PNG文件格式具体解释
  4. 【二叉树-&gt;链表】二叉树结构转双向线性链表结构(先序遍历)
  5. Linux学习之(())操作符
  6. 照着例子学习protobuf-python
  7. jq实战-表单验证
  8. GIS制图课程目录(持续整理)
  9. 对于996.ICU这个热门话题,一个在校学生的思考
  10. 零基础开发一款微信小程序商城
  11. php使用protobuf3
  12. Android:剖析源码,随心所欲控制Toast显示
  13. eclipse中添加jstl标签支持(引入头)
  14. Action访问Servlet API的三种方法
  15. jQuery选择元素的方法大全
  16. OpenGL纹理
  17. android 读取本地json文件 解决显示乱码显示
  18. Hibernate3.3.2_JUnit_BoforeClass不报异常的Bug处理
  19. Integer IntegerCache源码
  20. golang实现模拟键盘按键

热门文章

  1. 牛客提高D2t2 幸运数字考试
  2. String中的CompareTo
  3. SPSS输出结果如何在word中设置小数点前面显示加0
  4. php+form表单的文件上传
  5. ALDS1_1_3_D Areas on the Cross-Section Diagram 遇见了几个有意思的语法问题
  6. [LeetCode] 4. Median of Two Sorted Arrays(想法题/求第k小的数)
  7. 关于static以及final关键字
  8. jsp(java server page)
  9. phpcms批量更新内容页只更新一点就返回问题
  10. &quot;源文件名长度大于文件系统支持的长度无法删除&quot;的解决方案