hdu 4082 Hou Yi's secret

题目大意:给定N个点,求能够组成的三角形中相似三角形的最大的数目


解题思路:判一下重点,然后就是各种枚举啊 然后考虑了各种情况 结果各种wrong啊 悲剧啊~~ 郁闷啊~~  精度卡的太…了  最后发现是因为开方损失了精度。


谨记谨记:以后计算几何的题尽量少开方!!!!!


代码实现:


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
#define EPS 1e-8
struct pt
{
    double x, y;
}p[50];
struct edg
{
    double o, p, q;
}edge[3000];

int num[3000];
int n;
int cnt;
void swap(double &a, double &b)
{

         double temp = a ;
         a = b;
         b = temp;
}
double dis(pt a, pt b)
{
     return (a.x - b.x) * (a.x - b.x) + (a.y- b.y) * (a.y - b.y);
}

bool judge(pt a, pt b, pt c)
{
     double d1 = sqrt(dis(a, b));
     double d2 = sqrt(dis(a, c));
     double d3 = sqrt(dis(b, c));
     if((d1 + d2 > d3) && (d2 + d3 > d1) && (d1 + d3 > d2)) return true;
     return false;
}

void Calc(pt a, pt b, pt c)
{

     double t1 = dis(a, b);
     double t2 = dis(b, c);
     double t3 = dis(a, c);
     if(t1 > t2) swap(t1, t2);
     if(t1 > t3) swap(t1, t3);
     if(t2 > t3) swap(t2, t3);
     edge[cnt].o = t1;
     edge[cnt].p = t2;
     edge[cnt].q = t3;

}

void init()
{
     cnt = 0;
     for(int i = 0; i< n; i ++)
     {
          for(int j = i + 1; j < n; j ++)
          {
               for(int z = j + 1; z < n; z ++)
               {
                    if(judge(p[i], p[j], p[z]))
                    {
                         Calc(p[i], p[j], p[z]);
                         cnt ++;
                    }
               }
          }
     }
}

bool judge2(edg a, edg b)
{
     if(((a.o * b.p) == (a.p * b.o)) && ((a.p * b.q) == (a.q * b.p)) && ((a.o * b.q) == (a.q * b.o)))
         return true;
     return false;
}
int main()
{

    while(~scanf("%d", &n) && n)
    {
         int cn = 0;
         double x, y;
         for(int i =0 ; i< n;i ++)
         {
                scanf("%lf %lf", &x, &y);
                bool flag= false;
                for(int j = 0;  j < cn; j ++)
                {
                     if(p[j].x == x  && p[j].y == y)
                     {
                          flag= true;
                          break;
                     }
                }
                if(!flag)
                {
                    p[cn].x = x;
                    p[cn].y = y;
                    cn ++;
                }

         }
         n = cn;
         init();

         memset(num, 0, sizeof(num));
         for(int i = 0; i < cnt; i ++)
         {
              for(int j = 0; j < cnt; j ++)
              {
                     if(judge2(edge[i], edge[j]))
                         num[i] ++;
              }
         }
         int ma = 0;
         for(int i = 0; i< cnt; i ++)
         {
              if(ma < num[i])
                  ma = num[i];
         }
         printf("%d\n", ma);
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值