zoj2270Shamans【凸包】
来源:互联网 发布:成就最高的女演员知乎 编辑:程序博客网 时间:2024/06/03 04:43
In the far bare land there lives a mysterious tribe. They suffer from drought every year but they stick to their faith in god that they will never leave their home land. To counter the dry weather the shamans in the tribe must pray during the hard time and hope the rain will be blessed for their production of food.
There are 4 chief shamans in the tribe and they each will choose a summit in the territory to proceed their praying. The area their spells taking effect will be the polygon they form, taking each of them a vertex of the polygon (as the god will see when he looks down from the high heavens). The land is quite full of pinch and punch and the tribe has recorded quite some peaks for the shamans to pray on. Of course a largest area is expected so before the shamans actually go out, they will choose 4 peaks among the many to achieve so.
Input
One integer in the first line, followed by a blank line, stating the number of test cases. There will be not more than 300 tests.
For each test case, the first line is an integer n (4 <= n <= 2000) will state the number of peaks. Then n lines follow each presents the position of a peak, with two integers x, y (-20000 <= x, y <= 20000).
The test cases will be separated by a single blank line.
Output
A floating point number with exactly 1 digit precision: maximum area the shamans can cover.
Sample Input
2
4
0 0
1 0
1 1
0 1
4
0 0
0 1
1 1
1 0
Sample Output
1.0
1.0
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#define eps 1e-8using namespace std;const int maxn=10010;struct point{double x,y;}A[maxn],result[maxn];int sig(double n){if(fabs(n)<=eps)return 0;if(n<0)return -1;return 1;}double dist(point p1,point p2){return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}double cp(point p1,point p2,point p3){return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);}bool cmp(point a,point b){double ans=cp(A[0],a,b);if(sig(ans)==0){return dist(A[0],a)-dist(A[0],b)<=0;}else return ans>0;}int main(){int t,i,j,n,k;scanf("%d",&t);while(t--){scanf("%d",&n);int pos=0;for(i=0;i<n;++i){scanf("%lf%lf",&A[i].x,&A[i].y);if(A[pos].y>=A[i].y){if(A[pos].y==A[i].y){if(A[pos].x>A[i].x)pos=i;}else pos=i;}}point temp=A[pos];A[pos]=A[0];A[0]=temp;sort(A+1,A+n,cmp);int top=1;result[0]=A[0];result[1]=A[1];for(i=2;i<n;++i){while(top&&cp(result[top-1],result[top],A[i])<0)top--;result[++top]=A[i];}int ans=top; for(i=n-2;i>=0;--i){ while(top>ans&&cp(result[top-1],result[top],A[i])<0)top--; result[++top]=A[i]; } double sum=0; for(i=0;i<top;++i){ for(j=i+1;j<top;++j){ double S,Sa=0,Sb=0; for(k=0;k<top;++k){ if(k==i||k==j)continue; double S=-0.5*cp(result[i],result[j],result[k]); if(sig(S)<0)Sa=max(Sa,-S); else Sb=max(Sb,S); } if(Sa==0||Sb==0)continue; sum=max(sum,Sa+Sb); } } printf("%.1lf\n",sum);}return 0;}
- zoj2270Shamans【凸包】
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包。
- 凸包
- { 凸包 }
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 【LWJGL2 WIKI】【基础篇】基础2:输入
- Iterator
- [SDOI2014][JZOJ3624]数数
- 10391compound words
- eclipse插件使用
- zoj2270Shamans【凸包】
- oracle中varchar类型的最大长度
- MFC VC++6.0列表控件的使用
- 文件操作与字符处理
- C语言数组与字符串初始化
- UIButton, UILabel, UITextField
- vs2012环境下,cocos2dx3.4 c++项目调用Lua的环境搭建
- JAVA图形界面(GUI)之事件处理机制
- BCache源码浅析之二数据结构与操作