UVA 4728 Squares(凸包+旋转卡壳)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267
【思路】
凸包+旋转卡壳
求出凸包,用旋转卡壳算出凸包的直径即可。
【代码】
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std; struct Pt {
int x,y;
Pt(int x=,int y=):x(x),y(y) {};
};
typedef Pt vec; vec operator - (Pt A,Pt B) { return vec(A.x-B.x,A.y-B.y); }
bool operator < (const Pt& a,const Pt& b) {
return a.x<b.x || (a.x==b.x && a.y<b.y);
}
bool operator == (const Pt& a,const Pt& b) {
return a.x==b.x && a.y==b.y;
} int Dot(vec A,vec B) { return A.x*B.x+A.y+B.y; }
int cross(vec A,vec B) { return A.x*B.y-A.y*B.x; }
int dist(Pt A,Pt B) {
return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);
} int n;
vector<Pt> ConvexHull(vector<Pt> p) {
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
int n=p.size();
int m=;
vector<Pt> ch(n+);
for(int i=;i<n;i++) {
while(m> && cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--) {
while(m>k && cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
ch.resize(m);
return ch;
} int diameter(vector<Pt> ps) { //旋转卡壳
vector<Pt> p=ConvexHull(ps);
int n=p.size();
if(n==) return ; //特殊情况处理
if(n==) return dist(p[],p[]);
p.push_back(p[]); //for u
int ans=;
for(int u=,v=;u<n;u++) {
for(;;) {
int diff=cross(p[u+]-p[u],p[v+]-p[v]);
if(diff<=) { //此时uv为对踵点
ans=max(ans,dist(p[u],p[v]));
if(!diff) ans=max(ans,dist(p[u],p[v+])); //平行
break;
}
v=(v+)%n;
}
}
return ans;
}
void read(int& x) {
char c=getchar();
while(!isdigit(c)) c=getchar();
x=;
while(isdigit(c))
x=x*+c-'' , c=getchar();
}
int main() {
int T;
read(T);
while(T--) {
int n; read(n);
vector<Pt> ps;
for(int i=;i<n;i++) {
int x,y,w;
read(x),read(y),read(w);
ps.push_back(Pt(x,y));
ps.push_back(Pt(x+w,y));
ps.push_back(Pt(x,y+w));
ps.push_back(Pt(x+w,y+w));
}
printf("%d\n",diameter(ps));
}
return ;
}
UVA 4728 Squares(凸包+旋转卡壳)的更多相关文章
- [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)
http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...
- Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)
题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...
- poj 2079 Triangle (二维凸包旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u Submit Stat ...
- poj 2187 Beauty Contest(二维凸包旋转卡壳)
D - Beauty Contest Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 2187 凸包+旋转卡壳
思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说 凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...
- 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳
因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...
- 【BZOJ-1069】最大土地面积 计算几何 + 凸包 + 旋转卡壳
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2707 Solved: 1053[Submit][Sta ...
- 【BZOJ】1069: [SCOI2007]最大土地面积(凸包+旋转卡壳)
http://www.lydsy.com/JudgeOnline/problem.php?id=1069 显然这四个点在凸包上,然后枚举两个点找上下最大的三角形即可. 找三角形表示只想到三分QAQ.. ...
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
随机推荐
- 2016.08.07计算几何总结测试day2
T1 bzoj: [Usaco2010 OPen]Triangle Counting 数三角形 看到这个题n那么大, 于是想到极角排序搞一搞,然而排完序后立马懵逼,完全不知道接下来应该怎么写.... ...
- map容器对象插入数据的4种方式
#include <string> #include <iostream> #include <map> #include <utility> u ...
- 九度OJ 1435 迷瘴
题目地址:http://ac.jobdu.com/problem.php?pid=1435 题目描述: 通过悬崖的yifenfei,又面临着幽谷的考验—— 幽谷周围瘴气弥漫,静的可怕,隐约可见地上堆满 ...
- js清空前后空格
function trim(sValue){ var lastValue=this.replace(/(^\s*)|(\s*$)/g,""); ...
- centOS tengine 安装后 不能访问的问题
1 安装方式跟在ubuntu下 安装一样.因为都是用源码 2 但安装好以后发现,局域网电脑访问不了!.原以为是安装错了.又装了一遍,还是不行,最终是iptables 没开放80端口... http: ...
- js 获取时间 new Date()详细介绍
javaScript系列:js中获取时间new Date()详细介绍 (2012-03-31 09:54:25) 转载▼ 标签: js时间 new date() 字符类型 转换 分类: study-j ...
- 服务器端启动soket多线程
方法一: Socket socket=null try{ ServerSocket serversocket=nwe ServerSocket(8080) while(true){ socket=se ...
- 在redis中查询一个KEY的值
写入某个key: set MPM_YYC_XTJ_0 "abcde" [set key value]
- 一个matlab数字图像处理程序的解释
clc; %clc是清除command window里的内容 clear all; %clear是清除workspace里的变量 close all; %close all来关闭所有已经打开的图像窗口 ...
- app应用程序本地化--备用
一.简介 * 使用本地化功能,可以轻松地将应用程序翻译成多种语言,甚至可以翻译成同一语言的多种方言 * 如果要添加本地化功能,需要为每种支持的语言创建一个子目录,称为”本地化文件夹”,通常使用.lpr ...