poj 2079 Triangle(旋转卡壳)
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 8917 | Accepted: 2650 |
Description
Input
Output
Sample Input
3
3 4
2 6
2 7
5
2 6
3 9
2 0
8 0
6 5
-1
Sample Output
0.50
27.00
Source
【思路】
凸包+旋转卡壳
旋转卡壳:先确定两个点,叉积寻找最大的第三点,然后改变第二个点继续。
Quote:求点集中的最大三角形面积,O(n) 的旋转卡壳,先凸包,然后选取开头三个点 p,q,r 开始旋转,注意 r 不超过第一个点,q 不超过 r,p 不超过 q 。每次做三次推进,先推进 r,使 pq 不动面积最大,然后推进 q,再推进 p,如果三次都没有推进过,r 推进一格。每次推进完一个点都更新一下面积最大值。
【代码】
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#define FOR(a,b,c) for(int a=(b);a<=(c);a++)
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 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);
}
vector<Pt> ConvexHull(vector<Pt> p) {
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
int n=p.size() , 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 n;
vector<Pt> p,ch; int RC() {
int n=ch.size();
int ans= , cur= , j,k;
Pt v;
FOR(i,,n-) {
j=(i+)%n , k=(j+)%n;
while(j!=i && k!=i) {
ans=max(ans,abs(cross(ch[j]-ch[i],ch[k]-ch[i])));
while(cross(ch[i]-ch[j],ch[(k+)%n]-ch[k])<) k=(k+)%n;
j=(j+)%n;
}
}
return ans;
} int main() {
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
while(scanf("%d",&n)== && n!=-) {
p.clear() , ch.clear();
int x,y;
FOR(i,,n) {
scanf("%d%d",&x,&y);
p.push_back(Pt(x,y));
}
ch=ConvexHull(p);
printf("%.2lf\n",RC()/2.0);
}
return ;
}
poj 2079 Triangle(旋转卡壳)的更多相关文章
- POJ 2079 Triangle [旋转卡壳]
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9525 Accepted: 2845 Descript ...
- POJ 2079 Triangle 旋转卡壳求最大三角形
求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...
- POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 7625 Accepted: 2234 Descript ...
- poj 2079 Triangle (二维凸包旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u Submit Stat ...
- poj 2079 Triangle,旋转卡壳求点集的最大三角形
给出一个点集,求顶点在点集中的最大的三角形面积. 我们知道这三角形的三个点肯定在凸包上,我们求出凸包之后不能枚举,由于题目n比較大,枚举的话要O(n^3)的数量级,所以採用旋转卡壳的做法: 首先枚举三 ...
- ●POJ 2079 Triangle
题链: http://poj.org/problem?id=2079 题解: 计算几何,凸包,旋转卡壳 复杂度O(N^2),(O(N)什么的就不说了,我觉得我看过的O(N)方法正确性都有问题,虽然有些 ...
- POJ 2187 凸包+旋转卡壳
思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说 凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...
- POJ 2079 Triangle (凸包+旋转卡壳)
[题目链接] http://poj.org/problem?id=2079 [题目大意] 给出一些点,求出能组成的最大面积的三角形 [题解] 最大三角形一定位于凸包上,因此我们先求凸包,再在凸包上计算 ...
- poj 2079 Triangle
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9835 Accepted: 2951 Descript ...
随机推荐
- Codevs 2776 寻找代表元(二分图匹配)
2776 寻找代表元 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 广州二中苏元实验学校一共有n个社团,分别用1到n编号. 广州二 ...
- 窗口 namedWindow(), destroyWindow(), destroyAllWindows()[OpenCV 笔记6]
void namedWindow(const string& winname, int flags=WINDOW_AUTOSIZE); 创建一个窗口.imshow直接指定窗口名,可以省去此函数 ...
- 4MLinux7.0 服务器配置详解 别名TheSSS
TheSSS download 特性:thttp,php5.5.1,mysql,vsftp,proxy,firewall,带rpm管理器.更新频繁. 官方帮助文件:View (新窗口打开) 发现国内4 ...
- 翻译:ECMAScript 5.1简介
简介 ECMAScript 5.1 (或仅 ES5) 是ECMAScript(基于JavaScript的规范)标准最新修正. 与HTML5规范进程本质类似,ES5通过对现有JavaScript方法添加 ...
- View和ViewGroup的区别 -- Touch事件处理
View.java源码: /frameworks/base/core/java/android/view/View.java View.java的 dispatchTouchEvent 方法: 经过一 ...
- 粘滞位(sticky bit)
linux特殊权限:setUid, setGid, 粘着位(sticky) (1)目录的X权限(执行) 文件的可执行权限很简单,也就是可否执行它的意思,但目录的执行权限又代表什么意思呢? 当然不可能是 ...
- Highchart :tooltip工具提示
Highcharts翻译系列之十六:tooltip工具提示tooltip工具提示 参数 描述 默认值 animation 启用或禁用提示的动画.这对大数据量的图表很有用 true background ...
- asp.net资料! (.NET) (ASP.NET)
使用SqlBulkCopy类加载其他源数据到SQL表 在数据回发时,维护ASP.NET Tree控件的位置 vagerent的vs2005网站开发技巧 ASP.NET2.0小技巧--内部控件权限的实现 ...
- Pentaho Data Integration (二) Spoon
上一篇:Pentaho Data Integration笔记 (一):安装 介绍 Spoon Intoduction site: http://wiki.pentaho.com/display/EAI ...
- ABAP打开TCODE
CALL FUNCTION 'TH_CREATE_MODE' EXPORTING transaktion = 'ZGNBWD001' EXCEPTIONS max_session ...