题意

PDF

就是求凸包点集的直径。

题解

当然选择旋转卡壳。

然后是实现上的技巧:

当Area(p[u], p[u+1], p[v+1]) <= Area(p[u], p[u+1], p[v])时停止旋转

即Cross(p[u+1]-p[u], p[v+1]-p[u]) - Cross(p[u+1]-p[u], p[v]-p[u]) <= 0

根据Cross(A,B) - Cross(A,C) = Cross(A,B-C)

化简得Cross(p[u+1]-p[u], p[v+1]-p[v]) <= 0

画个图就能发现,这样找的是对于一条边三角形的最大高。为什么这样是对的呢?

凸包上一个点到其他点的距离是一个凸函数。然后在两条直线慢慢旋转的过程中,可以考虑直接转一条边,这样求出的是到这条直线的最大距离,显然就是对踵点对。

实现的时候初始化可以直接暴力转,因为均摊是\(O(n)\)的。时间复杂度\(O(T n \log n)\)。


由于坐标都是整数,而又不涉及需要实数运算的操作,所以`Point`类可以直接实现为整数坐标。
```cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define rg register
#define il inline
#define co const
templateil 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;
}
templateT read(T&x)
{
return x=read();
}
using namespace std;
typedef long long ll;

struct Point

{

int x,y;

Point(int x=0,int y=0)
:x(x),y(y){} bool operator<(co Point&rhs)co
{
return x<rhs.x||(x==rhs.x&&y<rhs.y);
} bool operator==(co Point&rhs)co
{
return x==rhs.x&&y==rhs.y;
}

};

typedef Point Vector;

Vector operator-(co Point&A,co Point&B)

{

return Vector(A.x-B.x,A.y-B.y);

}

int Cross(co Vector&A,co Vector&B)

{

return A.xB.y-A.yB.x;

}

int Dot(co Vector&A,co Vector&B)

{

return A.xB.x+A.yB.y;

}

int Dist2(co Vector&A,co Vector&B)

{

return (A.x-B.x)(A.x-B.x)+(A.y-B.y)(A.y-B.y);

}

vectorConvexHull(vector&p)

{

sort(p.begin(),p.end());

p.erase(unique(p.begin(),p.end()),p.end());

int n=p.size();
int m=0;
vector<Point>ch(n+1);
for(int i=0;i<n;++i)
{
while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
--m;
ch[m++]=p[i];
}
int k=m;
for(int i=n-2;i>=0;--i)
{
while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
--m;
ch[m++]=p[i];
}
if(n>1)
--m;
ch.resize(m);
return ch;

}

int Diameter2(vector&points)

{

vectorp=ConvexHull(points);

int n=p.size();

if(n1)

return 0;

if(n2)

return Dist2(p[0],p[1]);

p.push_back(p[0]); // avoid %

int ans=0;

for(int u=0,v=1;u<n;++u)

{

for(;

LA4728 Squares的更多相关文章

  1. [LeetCode] Word Squares 单词平方

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  2. 卡通图像变形算法(Moving Least Squares)附源码

    本文介绍一种利用移动最小二乘法来实现图像变形的方法,该方法由用户指定图像中的控制点,并通过拖拽控制点来驱动图像变形.假设p为原图像中控制点的位置,q为拖拽后控制点的位置,我们利用移动最小二乘法来为原图 ...

  3. Leetcode: Word Squares && Summary: Another Important Implementation of Trie(Retrieve all the words with a given Prefix)

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  4. [LintCode] Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  5. HDU 1264 Counting Squares(线段树求面积的并)

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. RSS(Residual Sum of Squares)的自由度为什么是n-1呢

    [转载请注明出处]http://www.cnblogs.com/mashiqi 在回归问题中,偶尔我们会遇到求方差的估计的情况.举了例子,我们常常通过Gaussian分布${\cal N}(\mu , ...

  7. poj-3739. Special Squares(二维前缀和)

    题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. ...

  8. [CareerCup] 7.5 A Line Cut Two Squares in Half 平均分割两个正方形的直线

    7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in ha ...

  9. POJ 2002 Squares

    二分.... Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 14530 Accepted: 5488 Descr ...

随机推荐

  1. 介绍Web项目中用到的几款表单验证插件

    第一个插件 jqueryvalidation 官网地址:http://jqueryvalidation.org/ 第二个插件 nice Validator 官网地址: http://niceue.co ...

  2. Java设计模式学习之工厂模式

    在Java(或者叫做面向对象语言)的世界中,工厂模式被广泛应用于项目中,也许你并没有听说过,不过也许你已经在使用了.Java 设计模式之工厂模式 简单来说,工厂模式的出现源于增加程序序的可扩展性,降低 ...

  3. CentOS6、7优化脚本完美版

    #!/bin/bash SysVer=`cat /etc/redhat-release | awk -F'release' '{print $2}' | awk -F'[ .]+' '{print $ ...

  4. spark学习14(spark local模式运行spark程序的报错)

    报错1 java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries. 解 ...

  5. Linux 利用管道父子进程间传递数据

    [原文] fork()函数:用于创建子进程,子进程完全复制父进程的资源,相当于父进程的拷贝.具体理解,运用父进程的同一套代码,通过判断进程ID来执行不同进程的不同任务. 返回值正常为子进程ID,出错返 ...

  6. geoserver源码学习与扩展——CSV转shapefile文件

    基于geotools实现csv转换为shapefile文件. 1.读取CSV文件,将其装入FeatureCollection: 2.利用ShapefileDumper类将FeatureCollecti ...

  7. ASP.NET动态生成GridView的使用

    根据DataTable动态生成包含checkbox的GridView,其中DataTable中对应checkbox那一列的值必须为bool值. public static GridView Dynam ...

  8. PHPAdmin的安装和配置

    phpadmin是用于管理mysql数据库的一个产品,,毕竟很多数据库服务器不能够公开连接,所以只能够使用http的方式来进行连接管理.     下载phpadmin( http://xj-http. ...

  9. EntityFramework之领域驱动设计实践

    EntityFramework之领域驱动设计实践 - 前言 EntityFramework之领域驱动设计实践 (一):从DataTable到EntityObject EntityFramework之领 ...

  10. D3.js学习笔记(三)——创建基于数据的SVG元素

    目标 在这一章,你将会使用D3.js,基于我们的数据来把SVG元素添加到网页中.这一过程包括:把数据绑定到元素上,然后在使用这些元素来可视化我们的数据. 注意:不同于前几章,我们从一个完整的代码开始, ...