呃,不知道我用的算不算卡壳,总有点枚举的意思。

先求凸包,然后,枚举其中一点,再枚举另一点作为结尾,这个向量旋转一周后,求出最大值面积。这里面用的是旋转卡壳判断的那个式子。

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的更多相关文章

  1. hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)

    链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

  2. ●POJ 2079 Triangle

    题链: http://poj.org/problem?id=2079 题解: 计算几何,凸包,旋转卡壳 复杂度O(N^2),(O(N)什么的就不说了,我觉得我看过的O(N)方法正确性都有问题,虽然有些 ...

  3. POJ 2079 Triangle (凸包+旋转卡壳)

    [题目链接] http://poj.org/problem?id=2079 [题目大意] 给出一些点,求出能组成的最大面积的三角形 [题解] 最大三角形一定位于凸包上,因此我们先求凸包,再在凸包上计算 ...

  4. poj 2079 Triangle(旋转卡壳)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 8917   Accepted: 2650 Descript ...

  5. POJ 2079 Triangle [旋转卡壳]

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9525   Accepted: 2845 Descript ...

  6. poj 2079(旋转卡壳求解凸包内最大三角形面积)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9060   Accepted: 2698 Descript ...

  7. POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 7625   Accepted: 2234 Descript ...

  8. POJ - 2079:Triangle (旋转卡壳,求最大三角形)

    Given n distinct points on a plane, your task is to find the triangle that have the maximum area, wh ...

  9. POJ 2079 最大三角形面积(凸包)

    Triangle Description Given n distinct points on a plane, your task is to find the triangle that have ...

随机推荐

  1. C++ 单例模式(读书笔记)

    #include <iostream> class Singleton {    static Singleton s;    int i;    Singleton(int x):i(x ...

  2. 数据结构C++,线性表的实现

    #include <iostream>#include <sstream>#include <fstream>#include <cmath>#incl ...

  3. CMS内容管理系统 -- WorkSpace

  4. Win10,JDK8,tomact7.0.85配置

    今天在win10上配置了jdk以及tomact先前使用jdk7+tomact7.0.56运行失败. 后经调整后正确配置注意事项如下: 1.下载并按照jdk-8u161-windows-x64,默认安装 ...

  5. 解决IE不支持Data.parse()的问题

    Date.parse()函数的返回值为Number类型,返回该字符串所表示的日期与 1970 年 1 月 1 日午夜之间相差的毫秒数. var nowtime = "2017-02-08&q ...

  6. A - Design Tutorial: Learn from Math(哥德巴赫猜想)

    Problem description One way to create a task is to learn from math. You can generate some random mat ...

  7. HBase的集群搭建(1、3、5节点都适用)

    见 5 hbase-shell + hbase的java api

  8. 如何通过putty软件远程登录并且控制linux平台

    准备备工作: 下载putty远程登录软件,图标如下 打开linux主机. Linux主机准备条件: 1 配置IP ,如果大家使用虚拟机的话建议通过vm1或者vm8进行与本地真实机进行连接,同时注意要避 ...

  9. ES:AI 注释

    为AI做注解: AI已经出第三版,大的框架没有改变,DNN也没有引入AI这本书.第四版网络版应流出,不知道最终定版如何! 强化学习的方法有大幅度更新,但从策略系统更新范畴看来,没有什么实质的改变,只是 ...

  10. Android使用NDK---函数参数传递-基本类型和数组

    参考链接:http://www.cnblogs.com/luxiaofeng54/archive/2011/08/19/2145486.html 数据传输可分为 基本数据类型传输 和 引用数据类型的传 ...