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. ASP.NET MVC 计划任务(不使用外接程序,.net内部机制实现)

    在asp.net中要不使用其他插件的情况下只能使用定时器来检查, 并执行任务. 以下讲解步骤: 1. 在Global.asax 文件中作如下修改 1 2 3 4 5 6 7 8 9 10 11 voi ...

  2. android&sqlsever

    http://blog.csdn.net/chaoyu168/article/details/51910601

  3. Apache Common Math Stat

    http://commons.apache.org/proper/commons-math/userguide/stat.html mark   DescriptiveStatistics maint ...

  4. JavaWeb开发如何用Tomcat部署发布

    一.如何安装TomCat 1.1安装包下载地址:https://tomcat.apache.org/download-70.cgi 1.2  安装exe文件,下一步直到安装成功.并启动Tomcat服务 ...

  5. 洛谷P3311 [SDOI2014]数数 AC自动机+dp

    正解:AC自动机+dp 解题报告: 传送门! 首先看到多串匹配balabala显然想到建个AC自动机? 然后可以用一点儿数位dp的思想地想下(,,,其实并不算QAQ 幸运数可以分为两类:位数<n ...

  6. 【pyqtgraph绘图】如何使用pyqtgraph

    解读官方API-如何使用pyqtgraph 这里有一些使用pyqtgraph的建议方法: 从交互式shell(python -i,ipython等) 从应用程序显示弹出窗口 在PyQt应用程序中嵌入小 ...

  7. 10种linux下磁盘快照方式恢复系统

    导读 大家都知道windows系统有一个磁盘快照的功能,在windows2003中系统恢复开始依赖于一个叫做硬盘快照服务(Volume Snapshot Service)的服务,他能够自动创建系统快照 ...

  8. 机器学习技术点----apachecn的github地址

    预处理 离散化 等值分箱 等量分箱 独热 one-hot 标准化 最小最大 min-max z-score l2 标准化 归一化 特征选择 ANOVA 信息增益/信息增益率 模型验证 评价指标 回归 ...

  9. fatal error: vector: No such file or directory

    jni/mac.cpp:28:18: fatal error: vector: No such file or directory jni/mac.cpp:29:18: fatal error: me ...

  10. The Swift Programming Language 中文版

    http://numbbbbb.github.io/the-swift-programming-language-in-chinese/