zoukankan      html  css  js  c++  java
  • 三个顶点可以组成什么正多边形——几何hdu 4195

    http://acm.hdu.edu.cn/showproblem.php?pid=4195

    组成多边形的边最小为多少

    1。先找三角形的垂心(注意线段垂直的情况)

    2。以垂心画圆YY,这个三角形可以把这个圆分成多少弧度(注意钝角三角形的第三边所对应的边的弧度为 2*PI的补数)

    3。接着枚举最小弧度的 n分之几,是否可以把其它弧度近似整除(如1801可以近似整除600)

    控制精度!!!

    View Code
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    using namespace std;

    double dis(double x,double y,double x1,double y1)
    {
    double dd=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));

    return dd;
    }

    int ha[100009];
    int add;

    double min(double a,double b)
    {
    if(a<b)return a;
    else return b;
    }

    int gcd(int m,int n)
    {
    int t;
    if(m<n){t=n,n=m,m=t;}
    while(n!=0)
    {
    t=m%n;
    m=n;
    n=t;
    }

    return m;
    }

    int main()
    {
    double x1,y1,x2,y2,x3,y3,k1,k2,xx1,yy1,xx2,yy2,xx,yy,r;
    char ss[199];
    while(scanf("%s",ss))
    {
    if(strcmp(ss,"END")==0)return 0;

    sscanf(ss,"%lf",&x1);
    scanf("%lf",&y1);
    scanf("%lf",&x2);
    scanf("%lf",&y2);
    scanf("%lf",&x3);
    scanf("%lf",&y3);

    double k1,k2,k3;
    double x,y;
    if(y2==y1||y3==y2)
    {
    if(y1==y2&&y2!=y3)
    {xx=(x1+x2)/2;
    k2=(x2-x3)/(y3-y2);
    xx2=(x2+x3)/2;
    yy2=(y2+y3)/2;
    yy=k2*(xx-xx2)+yy2;
    }
    if(y1!=y2&&y2==y3)
    {
    xx=(x2+x3)/2;
    k1=(x1-x2)/(y2-y1);
    xx1=(x1+x2)/2;
    yy1=(y1+y2)/2;
    yy=k1*(xx-xx1)+yy1;
    }
    }
    else
    {
    k1=(x1-x2)/(y2-y1);
    k2=(x2-x3)/(y3-y2);
    xx1=(x1+x2)/2;
    yy1=(y1+y2)/2;
    xx2=(x2+x3)/2;
    yy2=(y2+y3)/2;
    xx=(xx1*k1-xx2*k2+yy2-yy1)/(k1-k2);
    yy=k1*(xx-xx1)+yy1;

    }

    r=sqrt((x1-xx)*(x1-xx)+(y1-yy)*(y1-yy));

    double l1,l2,l3;
    l1=dis(x1,y1,x2,y2);
    l2=dis(x2,y2,x3,y3);
    l3=dis(x3,y3,x1,y1);

    double th1,th2,th3;

    double temp=(2*r*r-l1*l1)*1.0/2/r/r;
    if(temp>1.0)temp=1.0;
    if(temp<-1.0)temp=-1.0;
    th1=acos(temp);

    temp=(2*r*r-l2*l2)*1.0/2/r/r;
    if(temp>1.0)temp=1.0;
    if(temp<-1.0)temp=-1.0;
    th2=acos(temp);

    temp=(2*r*r-l3*l3)*1.0/2/r/r;
    if(temp>1.0)temp=1.0;
    if(temp<-1.0)temp=-1.0;
    th3=acos(temp);
    if(th1<th2)
    temp=th1,th1=th2,th2=temp;
    if(th1<th3)
    temp=th1,th1=th3,th3=temp;

    if(th1-(th2+th3)<0.00000001)
    th1=2*acos(-1.0)-th2-th3;

    int i,j,k;

    int max=1,shi1;
    double xiao=min(min(th1,th2),th3);

    add=0;
    int num;
    while(1)
    {
    add++;
    double temp=xiao*1.0/add;
    if(fabs(th1/temp-(int)(th1/temp+0.0001))>0.0001)continue;
    if(fabs(th2/temp-(int)(th2/temp+0.0001))>0.0001)continue;
    if(fabs(th3/temp-(int)(th3/temp+0.0001))>0.0001)continue;
    num=(th1+0.0001)/temp+(th2+0.0001)/temp+(th3+0.0001)/temp;
    break;
    }

    printf("%d\n",num);

    }
    return 0;
    }



  • 相关阅读:
    day30---内置函数
    day30---绑定方法与非绑定方法
    元类以及属性查找
    python 内置方法/魔法方法
    python 面向对象高级-反射机制
    centos7下jenkins升级
    屏蔽百度右侧热搜
    centos7部署汉化版gitlab
    CentOS 7 安装 Jenkins
    centos7安装与配置ansible
  • 原文地址:https://www.cnblogs.com/huhuuu/p/2430197.html
Copyright © 2011-2022 走看看