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

poj 1569 Myacm Triangles

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

poj 1569 Myacm Triangles

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;struct point{    double x;    double y;}p[20];struct T{    int xx;//    int yy;//    int zz;//    double mianji;//}res;bool cmp(int a,int b){    return a<b;}point operator-(const point &a,const point &b){    point temp;    temp.x=a.x-b.x;    temp.y=a.y-b.y;    return temp;}double operator*(const point &a,const point &b){    return fabs(a.x*b.y-b.x*a.y);}double cal(point a,point b,point c){    point m=b-a;    point n=c-a;    return m*n/2;}double cal2(point a,point b,point c,point d){    point m=c-d;    point n=a-d;    point h=b-d;    return m*n/2+m*h/2+n*h/2;}int main(){    int n;    while(scanf("%d",&n),n)    {        res.xx=-1;        res.yy=-1;        res.zz=-1;        res.mianji=0;        getchar();        int i,j,k,l;        char ch;        for(i=0;i<n;i++)        { scanf("%c",&ch); scanf("%lf %lf",&p[i].x,&p[i].y); getchar();        }        double mianji1,mianji2;        for(i=0;i<n;i++)        { for(j=i+1;j<n;j++) {     for(k=j+1;k<n;k++)     {         //由p[i],p[j],p[k]组成的三角形         mianji1=cal(p[i],p[j],p[k]);         bool flag=true;         for(l=0;l<n;l++)         {  if(l==i||l==j||l==k)  {      continue;  }  mianji2=cal2(p[i],p[j],p[k],p[l]);  if(mianji1==mianji2)  {      flag=false;      break;  }         }         if(flag)//三角形合法         {  if(mianji1>res.mianji)  {      res.xx=i;      res.yy=j;      res.zz=k;      res.mianji=mianji1;  }         }     } }        }        int h[3];        h[0]=res.xx;        h[1]=res.yy;        h[2]=res.zz;        sort(h,h+3,cmp);        printf("%c%c%cn",h[0]+'A',h[1]+'A',h[2]+'A');    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373907.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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