HDU 4082 Hou Yi's secret (几何,求相似三角形个数,暴力枚举,map记录)

 

Hou Yi's secret

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


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.
HDU 4082 Hou Yi's secret (几何,求相似三角形个数,暴力枚举,map记录)

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
 
 
2011年北京现场赛的题目。。。
很坑,WA了很多次。
对现场赛1A的无限膜拜啊。。。。
 
要去除重复的点。和共线的情况。
注意精度。
我是用map来记录角度来计数的,从而输出相似的三角形。
/*

数相似三角形个数

用map记录角度

注意:

1、去除重点

2、排除共线的情况

3、精度问题。



WA了8次了

*/



#include<stdio.h>

#include<math.h>

#include<map>

#include<iostream>

#include<string.h>

using namespace std;

const double eps=1e-6;

map<long long,int>mp;

struct Node

{

    int x,y;

}node[50];



double dis(Node a,Node b)

{

    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

}



void solve(Node a,Node b,Node c)

{

    double la=dis(b,c);

    double lb=dis(a,c);

    double lc=dis(a,b);

    if(la+lb<=lc+eps)return;

    if(lb+lc<=la+eps)return;

    if(la+lc<=lb+eps)return;

    double A=acos((lb*lb+lc*lc-la*la)/(2*lb*lc));

    double B=acos((la*la+lc*lc-lb*lb)/(2*la*lc));

    double C=acos((la*la+lb*lb-lc*lc)/(2*la*lb));

    if(A<eps||B<eps||C<eps)return;

    int t1=(int)(A*10000);

    int t2=(int)(B*10000);

    int t3=(int)(C*10000);

    if(t1>t2)swap(t1,t2);

    if(t1>t3)swap(t1,t3);

    if(t2>t3)swap(t2,t3);

    if(t1==0)return;

    long long t=t1*1000000*1000000+t2*1000000+t3;

    mp[t]++;

}

int hole[220][220];

int main ()

{

    int n;

    while(scanf("%d",&n),n)

    {

        int t=0;

        memset(hole,0,sizeof(hole));

        for(int i=0;i<n;i++)

        {

            scanf("%d%d",&node[t].x,&node[t].y);

            if(hole[node[t].x+100][node[t].y+100]==0)

            {

                hole[node[t].x+100][node[t].y+100]=1;

                t++;

            }

        }

        n=t;

        mp.clear();

        for(int i=0;i<n;i++)

          for(int j=i+1;j<n;j++)

            for(int k=j+1;k<n;k++)

              solve(node[i],node[j],node[k]);

        int ans=0;

        map<long long,int>::iterator it;

        for(it=mp.begin();it!=mp.end();it++)

        {

            int t=it->second;

            if(t>ans)ans=t;

        }

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

    }

    return 0;

}

 

你可能感兴趣的:(map)