hdu 4082 Hou Yi's secret(水题但暴露了自己的一些问题)

Hou Yi's secret

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1949    Accepted Submission(s): 474


Problem Description
Long long ago, in the time of Chinese emperor Yao, ten suns rose into the sky. They burned the crops and scorched the bushes and trees, leaving the people with nothing to eat.

Hou Yi was the greatest archer at that time. Yao wanted him to shoot down nine suns. Hou Yi couldn't do that job with ordinary arrows. So Yao send him to God to get some super powerful magic arrows. Before Hou Yi left, Yao said to him: "In order to manage our country in a better way, I want to know how many years can I live from now on. Please ask God this question for me." Hou Yi promised him.
Hou yi came back from God with ten magic arrows. He shot down nine suns, and the world returned to harmony. When Yao asked Hou Yi about the answer of his question, Hou Yi said: "God told me nothing. But I happened to see a 'life and death book' with your name on it. So I know the answer. But you know, I can't tell you because that's God's secret, and anyone who gives out God's secret will be burned by a thunder!"
Yao was very angry, he shouted: "But you promised me, remember?" Hou Yi said:
"Ooo-er, let's make some compromise. I can't tell you the answer directly, but I can tell you by my only precious magic arrow. I'll shoot the magic arrow several times on the ground, and of course the arrow will leave some holes on the ground. When you connect three holes with three line segments, you may get a triangle. The maximum number of similar triangles you can get means the number of years you can live from now on." (If the angles of one triangle are equal to the angles of another triangle respectively, then the two triangles are said to be similar.)
Yao was not good at math, but he believed that he could find someone to solve this problem. Would you help the great ancient Chinese emperor Yao?
 

Input
There are multiple test cases, and the number of test cases is no more than 12.
The first line of every test case is an integer n meaning that Hou Yi had shot the magic arrow for n times (2 < n <= 18).
Then n lines follow. Each line contains two integers X and Y (-100 < X, Y < 100), the coordinate of a hole made by the magic arrow.
Please note that one hole can be the vertex of multiple triangles.
The input ends with n = 0.
 

Output
For each test case, print a line with an integer indicating the maximum number of similar triangles Yao could get.
 

Sample Input
  
  
3 1 1 6 5 12 10 4 0 0 1 1 2 0 1 -1 0
 

Sample Output
  
  
1 4
 

Source
 

Recommend
lcy
 

题意:

很简单就不赘述了。

思路:

枚举三个点。判断是否共线。若共线则不能构成三角形剔除。不共线用结构体记录下来。

然后枚举一三角形再判断它与其它三角形是否相似。

总结:

此题暴露出了自己很多问题。

处理浮点数要注意精度问题。而且判断两个浮点数是否相等不能简单的==解决。

写程序要严谨。不能偷懒嫌麻烦。对于判重这种加了不会错。不加可能会错的情况应该严谨一些。

自己写程序太粗心。常常会为一个小小的问题像while()循环多加个分号。memset(a,0,sizeof 0)这些低级问题

纠结半天。

胆子太小。一看到有些麻烦的题目就不想深入研究。需要提高自己的实力很信心。

总之。要加油啊!!

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
const double eps=0.00000001;
using namespace std;
struct po//点类
{
    double x;
    double y;
} p[30];
double dis(po a,po b)//计算两点之间距离
{
    double x=b.x-a.x;
    double y=b.y-a.y;
    return sqrt(x*x+y*y);
}
bool qual(double a,double b)//判断两个浮点数是否相等
{
    if(fabs(a-b)<eps)
        return true;
    else
        return false;
}
class tra//三角形类
{
public:
    double l[3];//三条边
    tra(po a,po b,po c)//用三个点构造一个三角形
    {
        l[0]=dis(a,b);
        l[1]=dis(a,c);
        l[2]=dis(b,c);
        sort(l,l+3);//升序
    }
    bool same(tra &tb)//判断相似
    {
        if(qual(l[0]*tb.l[2],tb.l[0]*l[2])&&qual(l[0]*tb.l[1],tb.l[0]*l[1]))
            return true;
        else
            return false;
    }
    tra() {}
} tran[100000];
int n,cnt,ptr,ans;
bool vis[100000];
bool use[300][300];
int main()
{
    int i,j,k,sum,a,b;

    while(scanf("%d",&n),n)
    {
        memset(vis,0,sizeof vis);
        memset(use,0,sizeof use);
        ptr=cnt=ans=0;
        for(i=0; i<n; i++)
        {
            scanf("%d%d",&a,&b);
            if(use[a+100][b+100])//注意判重点!!!
                continue;
            use[a+100][b+100]=true;
            p[ptr].x=a;
            p[ptr++].y=b;
        }
        for(i=0; i<ptr; i++)
            for(j=i+1; j<ptr; j++)
                for(k=j+1; k<ptr; k++)
                {
                    if(qual((p[j].y-p[i].y)*(p[k].x-p[i].x),(p[k].y-p[i].y)*(p[j].x-p[i].x)))
                        continue;//判断三点共线
                    tran[cnt++]=tra(p[i],p[j],p[k]);
                }
        for(i=0; i<cnt; i++)//统计相似三角形
        {
            sum=1;
            for(j=i+1; j<cnt; j++)
            {
                if(tran[i].same(tran[j])&&!vis[j])
                {
                    sum++;
                    vis[j]=true;
                }
            }
            if(sum>ans)
                ans=sum;
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*
6
-1 -1
1 1
1 2
2 2
4 4
4 2
5
0 0
1 0
0 1
2 0
0 2
6
1 1
2 2
3 1
1 3
3 3
4 2
5
1 1
1 3
3 1
3 3
2 2
6
1 1
1 1
1 3
3 1
3 3
2 2
5
0 0
3 0
100 0
0 3
0 100
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值