hdu 4082 Hou Yi's secret 统计相似三角形 暴力

来源:互联网 发布:淘宝产品评价怎么写 编辑:程序博客网 时间:2024/05/29 04:02

Hou Yi's secret

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


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
31 16 512 1040 01 12 01 -10

Sample Output
14

Source
2011 Asia Beijing Regional Contest 



/*1,经测试,有重点2,用整数计算3,考虑三点共线的情况*/#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define N 19#define NT 1001int hole[222][222];struct point{    int x,y;    int input()    {        scanf("%d%d",&x,&y);        if(hole[x+100][y+100])            return 0;        hole[x+100][100+y] = 1;        return 1;    }}p[N];int dist(point a,point b){    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);}struct triangle{    int edge[3];    void get_edge(point a,point b,point c)    {        edge[0] = dist(a,b);        edge[1] = dist(a,c);        edge[2] = dist(b,c);        sort(edge,edge+3);    }}tri[NT];bool similiar(triangle s1,triangle s2){    return (s1.edge[0] * s2.edge[1] == s1.edge[1] * s2.edge[0])&&           (s1.edge[0] * s2.edge[2] == s1.edge[2] * s2.edge[0])&&           (s1.edge[1] * s2.edge[2] == s1.edge[2] * s2.edge[1]);}bool nline(point a,point b,point c){    int x1 = b.x - a.x, y1 = b.y - a.y,        x2 = c.x - a.x, y2 = c.y - a.y;    return x1 * y2 != x2 * y1;}int main(){    int n,i,j,k,st;    int cal[NT] = {0},temp;    while(scanf("%d",&n) != EOF && n)    {        memset(hole,0,sizeof(hole));        memset(cal,0,sizeof(cal));        for(i = 0; i < n; ++i)//            p[i].input();            if(!p[i].input())                --i,--n;        st = 0;        for(i = 0; i < n; ++i)            for(j = i + 1; j < n; ++j)                for(k = j + 1; k < n; ++k)                if(nline(p[i],p[j],p[k]))                    tri[st++].get_edge(p[i],p[j],p[k]);        int sum = 0;        for(i = 0; i < st; ++i)            if(!cal[i])            {                temp = 1;                cal[i] = 1;                for(j = i + 1; j < st; ++j)                    if(!cal[j] && similiar(tri[i],tri[j]))                    {                        ++temp;                        cal[j] = 1;                    }                if(temp > sum)                    sum = temp;            }        printf("%d\n",sum);    }    return 0;}