POJ 2079
呃,不知道我用的算不算卡壳,总有点枚举的意思。
先求凸包,然后,枚举其中一点,再枚举另一点作为结尾,这个向量旋转一周后,求出最大值面积。这里面用的是旋转卡壳判断的那个式子。
PS:下一篇和这题是一样题意,但用这题的写法去过下一题,是过不了的。但这个写法在POJ 上是400MS,而下一题的写法在POJ上是1000MS。。汗了。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath> using namespace std; struct point{
int x,y;
}p[50050];
int n; int ans[50050],st[50050],cnt,stop; bool cmp(point A, point B){
if(A.y<B.y) return true;
else if(A.y==B.y){
if(A.x<B.x) return true;
}
return false;
} int multi(point a,point b,point c){
point p1; p1.x=a.x-c.x; p1.y=a.y-c.y;
point p2; p2.x=b.x-c.x; p2.y=b.y-c.y;
return p1.x*p2.y-p1.y*p2.x;
} void slove(){
cnt=stop=0;
st[stop++]=0; st[stop++]=1;
for(int i=2;i<n;i++){
while(stop>1&&multi(p[i],p[st[stop-1]],p[st[stop-2]])>0) stop--;
st[stop++]=i;
}
for(int i=0;i<stop;i++)
ans[cnt++]=st[i];
stop=0; st[stop++]=n-1; st[stop++]=n-2;
for(int i=n-3;i>=0;i--){
while(stop>1&&multi(p[i],p[st[stop-1]],p[st[stop-2]])>0) stop--;
st[stop++]=i;
}
for(int i=1;i<stop;i++)
ans[cnt++]=st[i];
} double Triangle(point a,point b,point c){
point p1; p1.x=a.x-c.x; p1.y=a.y-c.y;
point p2; p2.x=b.x-c.x; p2.y=b.y-c.y;
return fabs((p1.x*p2.y-p1.y*p2.x)*1.0)/2.0;
} double Area(){
int q;
double anst=0;
for(int i=0;i<cnt;i++){
q=i+1;
for(int j=i+1;j<cnt;j++){
while(Triangle(p[ans[i]],p[ans[j]],p[ans[q]])<Triangle(p[ans[i]],p[ans[j]],p[ans[(q+1)%cnt]]))
q=(q+1)%cnt;
anst=max(anst,Triangle(p[ans[i]],p[ans[j]],p[ans[q]]));
}
}
return anst;
} int main(){
while(scanf("%d",&n)!=EOF){
if(n==-1) break;
for(int i=0;i<n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
sort(p,p+n,cmp);
slove();
double anst=0;
anst=max(anst,Area());
printf("%.2lf\n",anst);
}
return 0;
}
POJ 2079的更多相关文章
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- ●POJ 2079 Triangle
题链: http://poj.org/problem?id=2079 题解: 计算几何,凸包,旋转卡壳 复杂度O(N^2),(O(N)什么的就不说了,我觉得我看过的O(N)方法正确性都有问题,虽然有些 ...
- POJ 2079 Triangle (凸包+旋转卡壳)
[题目链接] http://poj.org/problem?id=2079 [题目大意] 给出一些点,求出能组成的最大面积的三角形 [题解] 最大三角形一定位于凸包上,因此我们先求凸包,再在凸包上计算 ...
- poj 2079 Triangle(旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 8917 Accepted: 2650 Descript ...
- POJ 2079 Triangle [旋转卡壳]
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9525 Accepted: 2845 Descript ...
- poj 2079(旋转卡壳求解凸包内最大三角形面积)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9060 Accepted: 2698 Descript ...
- POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 7625 Accepted: 2234 Descript ...
- POJ - 2079:Triangle (旋转卡壳,求最大三角形)
Given n distinct points on a plane, your task is to find the triangle that have the maximum area, wh ...
- POJ 2079 最大三角形面积(凸包)
Triangle Description Given n distinct points on a plane, your task is to find the triangle that have ...
随机推荐
- Organize Your Train part II(hash)
http://poj.org/problem?id=3007 第一次用STL做的,TLE了,自己构造字符串哈希函数才可以.. TLE代码: #include <cstdio> #inclu ...
- [Apple开发者帐户帮助]五、管理标识符(5)创建一个iCloud容器
您必须拥有一个或多个iCloud容器才能启用iCloud. 所需角色:帐户持有人或管理员. 在“ 证书”,“标识符和配置文件”中,从左侧的弹出菜单中选择操作系统. 在“标识符”下,选择“iCloud容 ...
- Speex回声消除原理深度解析
这里假设读者具有自适应滤波器的基础知识.Speex的AEC是以NLMS为基础,用MDF频域实现,最终推导出最优步长估计:残余回声与误差之比.最优步长等于残余回声方差与误差信号方差之比,这个结论可以记下 ...
- Android Gradle 学习笔记(七):Android Gradle 插件
我们知道Android Gradle其实就是一个Gradle的一个第三方插件,它是由Google的Android团队开发的,基于Gradle构建的,和Android Studio完美搭配.相比于旧的构 ...
- C#中动态读取配置
有些时候,文件修改需要及时的响应,这个时候就需要实时读取文件,预先想的是写一个计时器,每隔多久运行一次,但是不能实时响应,所以采用监听文件的方式实现读取数据 C#监听文件变化 /// <summ ...
- 「LOJ10150」括号配对
[题目] Hecy 又接了个新任务:BE 处理.BE 中有一类被称为 GBE. 以下是 GBE 的定义: 空表达式是 GBE 如果表达式 A 是 GBE,则 [A] 与 (A) 都是 GBE 如果 A ...
- [转载]cocos2d-触摸分发原理
本文由泰然翻译组组长 TXX_糖炒小虾 原创,版权所有,转载请注明出处并通知作者和泰然! 原作 http://www.ityran.com/archives/1326/comment-page-1 触 ...
- 重装系统后快速安装.NET 3.5
每一次重装系统(Windows 8.1 和Windows 10)之后,最让我头疼的一件事就是配置把一大堆软件装上了.通常我会装好SQL Server之后,把电脑放在工作组安装Visual Studio ...
- 3.0 Windows和Linux双系统安装(3)
3.0 Windows和Linux双系统安装(3) 3.1 精简的安装步骤如下:(如果已经有了前面两篇教程的安装经验,推荐看完3.1即可动手了) 双系统很多开发新人会用到,而且比起虚拟机好处是运行效率 ...
- android黑科技系列——Android中新型安全防护策略
一.前言 最近有一个同学,发给我一个设备流量访问检测工具,但是奇怪的是,他从GP上下载下来之后安装就没有数据了,而在GP上直接安装就可以.二次打包也会有问题.所以这里就可以判断这个app应该是有签名校 ...