bsoj 2044 【SCOI2007】最大土地面积
2016-02-20 14:47
344 查看
Description
在某块平面土地上有n个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大
Input
第1行一个正整数n,接下来n行,每行2个数x、y,表示该点的横坐标和纵坐标。
Output
最大的多边形面积,答案精确到小数点后3位。
Sample Input
5 0 0 1 0 1 1 0 1 0.5 0.5
Sample Output
1.000
Hint
【数据范围】n<=2000,|x|,|y|<=100000
枚举对角线时,再枚举1个点得到对角线与此点的三角形最大面积和最小面积。
一次旋转卡壳即可算出。。居然在OJ上rank1了呢☺☺☺☺☺☺☺☺☺☺~~~~~~
旋转卡壳升级版:
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; struct Vector{ double x,y; Vector operator +(Vector &a){ Vector v1; v1.x=this->x+a.x,v1.y=this->y+a.y; return v1; }; Vector operator -(Vector &a){ Vector v1; v1.x=this->x- a.x,v1.y=this->y -a.y; return v1; }; double operator * (Vector &a){ return ((this->x)*a.y)-(a.x*(this->y)); }; }P[500055] ; int n; int ch[500005]; bool vis[500005]; int top=0; bool cmp(Vector a,Vector b){ return (a.y<b.y)||((a.y==b.y)&&(a.x<b.x)); } bool Judge(Vector a,Vector b,Vector c){ Vector q=b-c; Vector w=a-c; return q*w>=0; } double Get_Area(Vector a,Vector b,Vector c){ a=a-c; b=b-c; return a*b; } double Get_Long(Vector a,Vector b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } void TUBao(){ sort(P+1,P+1+n,cmp); ch[++top]=1; int k=2; while(k<=n){ while(top>1&&Judge(P[ch[top]],P[k],P[ch[top-1]])) vis[ch[top--]]=0; ch[++top]=k; vis[k]=1; k++; } int Max=top; k=n-1; while(k>=1){ while(vis[k])k--; while(top>Max&&Judge(P[ch[top]],P[k],P[ch[top-1]])) vis[ch[top--]]=0; ch[++top]=k; vis[k]=1; k--; } } void Rotating_calipers(){ int p=2; double ans=0.0; for(int q=1;q<top;q++){ while(Get_Area(P[ch[q]],P[ch[q+1]],P[ch[p+1]])>Get_Area(P[ch[q]],P[ch[q+1]],P[ch[p]])){ p=(p+1)%top; if(p==0)p=1; } double Max=0.0; double Min=1e8; for(int i=1;i<top;i++)if(i!=q&&i!=p){ double Temp=Get_Area(P[ch[p]],P[ch[i]],P[ch[q]]); Max=max(Max,Temp); Min=min(Min,Temp); } ans=max(ans,Max/2-Min/2); } printf("%.3lf",ans); } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%lf%lf",&P[i].x,&P[i].y); } TUBao(); Rotating_calipers(); return 0; }
[/code]
相关文章推荐
- 【Lintcode】Median of two Sorted Arrays
- 选择本地图片上传到服务器进行头像设置以及文件下载
- 通用刷新数据源代码
- The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemK:Kinds of Fuwas
- 如何在 Go 语言中使用 Redis 连接池-Radix.v2
- 【C语言】文件常用读写操作(含读取学生信息示例)
- [UVA1368]DNA Consensus String
- Educational Codeforces Round 8
- 10、Maven插件源码的下载方法
- ACM解题总结——HihoCoder1153
- linux 下使用 tc 模拟网络延迟和丢包
- 故乡的云
- iOS调试技巧—调试状态修改UI
- 开发环境配置(三) 局域网中其他机器不能访问本机IIS网站
- 我使用过的Linux桌面发行版
- Unity3D研究院编辑器之打开unity不可识别的文件
- HDU 1522 Marriage is Stable 稳定婚姻问题 (再水一发)
- 牛人的github
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
- bsoj1156 【CQOI2006】 凸多边形