栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2419 Triangle

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2419 Triangle

#include <queue>#include <stack>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <string>#include <algorithm>using namespace std;const int MAX = 50010;const double eps = 1e-6;bool dy(double x,double y){return x > y + eps;}// x > y bool xy(double x,double y){return x < y - eps;}// x < y bool dyd(double x,double y){ return x > y - eps;}// x >= y bool xyd(double x,double y){return x < y + eps;} // x <= y bool dd(double x,double y) {return fabs( x - y ) < eps;}  // x == ystruct point{double x,y;};point c[MAX],stk[MAX];int top;double crossProduct(point a,point b,point c){return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y);}double disp2p(point a,point b) {return sqrt( ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) );}bool cmp(point a,point b)  {      double len = crossProduct(c[0],a,b);      if( dd(len,0.0) )          return xy(disp2p(c[0],a),disp2p(c[0],b));      return xy(len,0.0);  }double area_***(point a,point b,point c){return fabs( crossProduct(a,b,c) )/2.0;}double max(double x,double y){return dy(x,y) ? x : y;}double RC(point *s,int n){int p,q,r;p = 0; q = 1; r = 2;double area = area_***(s[p],s[q],s[r]);while(1){int pp = p,qq = q,rr = r;while( xy(fabs(crossProduct(s[p],s[q],s[r])),fabs(crossProduct(s[p],s[q],s[(r+1)%n])))){area = max(area,area_***(s[p],s[q],s[(r+1)%n]));r = (r+1)%n;}while( xy(fabs(crossProduct(s[p],s[q],s[r])),fabs(crossProduct(s[p],s[(q+1)%n],s[r])))){area = max(area,area_***(s[p],s[(q+1)%n],s[r]));q = (q+1)%n;}while( xy(fabs(crossProduct(s[p],s[q],s[r])),fabs(crossProduct(s[(p+1)%n],s[q],s[r])))){area = max(area,area_***(s[(p+1)%n],s[q],s[r]));p = (p+1)%n;}if( pp == p && qq == q && rr == r ) r = (r+1)%n;if( r == 0 ) return area;}}double Graham(int n){    int tmp = 0;      for(int i=1; i<n; i++)    if( xy(c[i].x,c[tmp].x) || dd(c[i].x,c[tmp].x) && xy(c[i].y,c[tmp].y) )    tmp = i;    swap(c[0],c[tmp]);    sort(c+1,c+n,cmp);    stk[0] = c[0]; stk[1] = c[1];    top = 1;for(int i=2; i<n; i++){while( xyd( crossProduct(stk[top],stk[top-1],c[i]), 0.0 ) && top >= 1 )top--;stk[++top] = c[i];}return RC(stk,top+1);}int main(){int n;while( ~scanf("%d",&n) && n != -1 ){for(int i=0; i<n; i++)scanf("%lf%lf",&c[i].x,&c[i].y);double ans = Graham(n);printf("%.2lfn",ans);}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374065.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号