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 ...
随机推荐
- DOM Ready 详解
DOM Ready 概述 熟悉jQuery的人, 都知道DomReady事件. window.onload事件是在页面所有的资源都加载完毕后触发的. 如果页面上有大图片等资源响应缓慢, 会导致wind ...
- yii2源码学习笔记(十八)
View继承了component,用于渲染视图文件:yii2\base\View.php <?php /** * @link http://www.yiiframework.com/ * @co ...
- linux curl命令验证服务器断点续传支持
有个同事说,发现现在对外下载安装包的服务器不支持断点续传,我听了一阵纳闷,lighttpd server对于静态文件应该默认支持断点续传的,登机器查看lighttpd配置文件发现 对断点续传的支持被禁 ...
- C语言和C++中动态申请内存
在C语言和C++的动态内存的使用方法是不同的,在C语言中要使用动态内存要包含一个头文件即 #include<malloc.h> 或者是#include<stdlib.h> ...
- C语言中调用Lua
C语言和Lua天生有两大隔阂: 一.C语言是静态数据类型,Lua是动态数据类型 二.C语言需要程序员管理内存,Lua自动管理内存 为了跨越世俗走到一起,肯定需要解决方案. 解决第一点看上去比较容易,C ...
- SpringMVC Maven创建项目
一.配置Maven环境: 1.去官网下载好Maven,并解压: 2.添加环境变量: ①添加环境变量,如下: ②把maven的bin目录添加到环境变量path下面,如下(我系统是win10,win7编辑 ...
- 定位 - CoreLocation - 区域报警
#import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewCont ...
- spring 下载地址(拷贝)
Spring2.5.6 和Spring3.0.5所有jar下载地址spring jar包 官方下载地址 文档下载地址.2.56版本 和3.05版本http://s3.amazonaws.com/dis ...
- 防御XSS攻击的七条原则
本文将会着重介绍防御XSS攻击的一些原则,需要读者对于XSS有所了解,至少知道XSS漏洞的基本原理,如果您对此不是特别清楚,请参考这两篇文章:<Stored and Reflected XSS ...
- 在安全层面,企业如何获得更好的投资回报率 ROI?
前言 任何企业对投资都有回报的要求,回报可能是直接的「利润」,达到短期.长期的目标,或者通过投资减少损失.因此每个项目的决策者在每笔投资前都要衡量 ROI,证明该投资能达到的效果和收益,以便在项目结束 ...