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 ...
随机推荐
- ios 64位下编译webrtc的libvpx库出现错误Bad cputype for object file.Currently only tested for CPU_TYPE_x86_64
diff --git a/libvpx.gyp b/libvpx.gypindex 4f8cb2b..4eb6866 100644--- a/libvpx.gyp+++ b/libvpx.gyp@@ ...
- Spark-Cassandra-Connector 插入数据函数saveToCassandra
在spark-shell中将数据保存到cassandra: var data = normalfill.map(line => line.split("\u0005")) d ...
- 用source code编译安装Xdebug
1. Unpack the tarball: tar -xzf xdebug-2.2.x.tgz. Note that you do not need to unpack the tarball i ...
- lnmp安装--php与nginx结合
软件环境: linux:centos5. nginx:.tar.gz php:.tar.gz lnmp与lamp的区别? lnmp(linux+nginx+mysql+php)的提法相对于lamp(l ...
- sirius的学习笔记(3)
毕业论文什么的终于搞完了,重拾我的python Creating the python skeleton project directory $ mkdir project $ cd project ...
- iOS 一些struct类型的NSLog输出格式-b
我们经常会输出一些坐标尺寸信息之类的,比如view的frame,是CGRect类型的,用frame.oringial.x 和frame.size.width来做NSLog参数好麻烦,还好苹果对这些常用 ...
- 如何创建一个自定义jQuery插件
简介 jQuery 库是专为加快 JavaScript 开发速度而设计的.通过简化编写 JavaScript 的方式,减少代码量.使用 jQuery 库时,您可能会发现您经常为一些常用函数重写相同的代 ...
- Session里的对象是不可靠的!
最近在做Database课程的final project,foodiePharos, 重新认识了JSP里容易出现的一些问题. 比如我们这个项目使用了JPA,就涉及到entity对象的状态问题,Enti ...
- hdu 4731
一道找规律的题,但今天的智商捉急,一直都想不到点子上: 比赛之后和别人讨论的时候,在n=2的情况下,前面两个是aa,后面就接着很多个aababb,然后最后再判断下就行了~~~ 以后对于这种题还是不要太 ...
- Google面试题之100层仍两个棋子
一道Google面试题,题目如下:"有一个100层高的大厦,你手中有两个相同的玻璃围棋子.从这个大厦的某一层扔下围棋子就会碎,用你手中的这两个玻璃围棋子,找出一个最优的策略,来得知那个临界层 ...