Squares

【题目链接】Squares

【题目类型】旋转卡壳

&题解:

听着算法名字,感觉挺难,仔细一看之后,发现其实很简单,就是依靠所构成三角行面积来快速的找对踵点,就可以省去很多的复杂度了.旋转的复杂度是O(n),之后还有计算每条边对应的对踵点复杂度平均大约O(n/2)在实际中也许可以更快

&代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std; struct Point {
int x,y;
Point(int x=0,int y=0): x(x),y(y) {}
};
typedef Point Vector;
Vector operator - (const Vector& A,const Vector& B) {return Vector(A.x-B.x , A.y-B.y);}
bool operator == (const Point& a,const Point& b) {return a.x==b.x&&a.y==b.y;}
bool operator < (const Point& a,const Point& b) {return a.x<b.x||(a.x==b.x&&a.y<b.y);}
int Cross(Vector A,Vector B) {return A.x*B.y - A.y*B.x;}
int Dist2(const Point& a,const Point& b) {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);} vector<Point> ConvexHull(vector<Point> p) {
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()) , p.end());
int n=p.size(), 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-1])<=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-1])<=0) m--;
ch[m++]=p[i];
}
if(m>1) m--;
ch.resize(m);
return ch;
} int diameter2(vector<Point>& points) {
vector<Point> p=ConvexHull(points);
int n=p.size();
if(n==1) return 0;
if(n==2) return Dist2(p[0] , p[1]);
p.push_back(p[0]);
int ans=0;
for(int u=0, v=1; u<n; u++) {
for(;;) {
int diff = Cross(p[u+1]-p[u] , p[v+1]-p[v]);
if( diff<=0 ) {
ans=max(ans , Dist2(p[u],p[v]));
//2个三角形面积相等
if(diff==0) ans=max(ans, Dist2(p[u], p[v+1]));
break;
}
v=(v+1)%n;
}
}
return ans;
} int main() {
freopen("E:1.in","r",stdin);
int T;
scanf("%d",&T);
while(T--) {
int n;
scanf("%d" ,&n);
vector<Point> po;
for(int i=0; i<n; i++) {
int x,y,w;
scanf("%d%d%d",&x,&y,&w);
po.push_back(Point(x,y));
po.push_back(Point(x+w,y));
po.push_back(Point(x,y+w));
po.push_back(Point(x+w,y+w));
}
printf("%d\n", diameter2(po));
}
return 0;
}

UVAL 4728 Squares(旋转卡壳)的更多相关文章

  1. UVALive 4728 Squares(旋转卡壳)

    Squares The famous Korean IT company  plans to make a digital map of the Earth with help of wireless ...

  2. UVa 1453 - Squares 旋转卡壳求凸包直径

    旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...

  3. LA 4728 (旋转卡壳) Squares

    题意: 求平面上的最远点对距离的平方. 分析: 对于这个数据量枚举肯定是要超时的. 首先这两个点一定是在凸包上的,所以可以枚举凸包上的点,因为凸包上的点要比原来的点会少很多,可最坏情况下的时间复杂度也 ...

  4. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

  5. LA 4728 旋转卡壳算法求凸包的最大直径

    #include<iostream> #include<cstdio> #include<cmath> #include<vector> #includ ...

  6. UVALive 4728 Squares (平面最远点对)

    题意:n个平行于坐标轴的正方形,求出最远点对的平方 题解:首先求出凸包,可以证明最远点对一定是凸包上的点对,接着可以证明最远点对(每个点的对踵点)一定只有3*n/2对 接着使用旋转卡壳找到最远点对,但 ...

  7. 1393: Robert Hood 旋转卡壳 凸包

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1393 http://poj.org/problem?id=2187 Beauty Contest ...

  8. POJ 3608 Bridge Across Islands --凸包间距离,旋转卡壳

    题意: 给你两个凸包,求其最短距离. 解法: POJ 我真的是弄不懂了,也不说一声点就是按顺时针给出的,不用调整点顺序. 还是说数据水了,没出乱给点或给逆时针点的数据呢..我直接默认顺时针给的点居然A ...

  9. 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳

    因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...

随机推荐

  1. MySQL的一些概念

    数据库与服务器.客户端的层次关系 关于数据库 程序中需要存储数据的方式: 1 变量(列表.元组.集合.字典.嵌套) 2 外存(文件)(*.ini) 3 表格.Excel(*.xls.*.xlsx.*. ...

  2. I do think I can breakdown the problem into parts that make sense

    RESTful Web APIs_2013 An API released today will be named after the company that hosts it. We talk a ...

  3. AutoMapper介绍(未完待续、部分没实现)

    实体间转换工具.其实也可以用Json来实现同名属性.异名属性(用JsonProperty指明)的自动转换 最新版本6.11 需要使用vs2013以上.vs2012下载新版 nuget会遇到问题.只能旧 ...

  4. Flink - watermark生成

    参考,Flink - Generating Timestamps / Watermarks watermark,只有在有window的情况下才用到,所以在window operator前加上assig ...

  5. easyUI表格多表头实现

    项目中要实现表格多表头,结合网上的例子自己实现了一个,包含frozenColumns情况. 一,通过标签创建 效果: <table id="schoolGrid" class ...

  6. jquery 数组的操作

    1.数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...

  7. 洛谷P3960 列队 NOIp2017 线段树/树状数组/splay

    正解:动态开点线段树 解题报告: 传送门! 因为最近学主席树的时候顺便get到了动态开点线段树?刚好想起来很久很久以前就想做结果一直麻油做的这题,,,所以就做下好了QAQ 然后说下,这题有很多种方法, ...

  8. git的配置操作

    git配置信息 一.配置git config git config user.name 'yourName' git config user.name 'yourEmail@gmail.com' 二. ...

  9. 【Linux】测试环境如何搭建?

    [Linux]测试环境如何搭建? (该文档所在我的百度网盘位置: ) 通常面试会问到会不会搭建测试环境?到底啥是测试环境搭建呢,其实测试环境没有想像的那么高大上,弄个 tomcat,把测试的 war ...

  10. c#4.0 Task.Factory.StartNew 用法

    var t1 = Task.Factory.StartNew<string>(() => { return “1111111”; }); //t1.Wait(); t1.Contin ...