zoukankan      html  css  js  c++  java
  • HDU 4082

    Hou Yi's secret

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

     

    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
     
    题意:
      给你N个点,求有多少个相似三角形问题,这题太坑了,做题需谨慎行事
    思路:
      仔细,仔细,再仔细,
    AC代码:
     1 # include <bits/stdc++.h>
     2 using namespace std;
     3 const int N = 20;
     4 const int Max = 1001;
     5 int vis[222][222];
     6 
     7 struct point
     8 {
     9     int x, y;
    10     
    11     int input()
    12     {
    13         scanf("%d%d", &x, &y);
    14         if(vis[x + 100][y + 100])
    15             return 0;
    16         vis[x + 100][100 + y] = 1;
    17         return 1;
    18     }
    19 }p[N];
    20 
    21 int dis2(point a, point b)
    22 {
    23     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
    24 }
    25 struct triangle
    26 {
    27     int num[3];
    28     void get_num(point a,point b,point c)
    29     {
    30         num[0] = dis2(a,b);
    31         num[1] = dis2(a,c);
    32         num[2] = dis2(b,c);
    33         sort(num, num + 3);
    34     }
    35 }tri[Max];
    36 // 判断相似
    37 bool Issimi(triangle s1, triangle s2)
    38 {
    39     return (s1.num[0] * s2.num[1] == s1.num[1] * s2.num[0])&&
    40            (s1.num[0] * s2.num[2] == s1.num[2] * s2.num[0])&&
    41            (s1.num[1] * s2.num[2] == s1.num[2] * s2.num[1]);
    42 }
    43 // 判断直线
    44 bool Isline(point a, point b, point c)
    45 {
    46     int x1 = b.x - a.x, y1 = b.y - a.y,
    47         x2 = c.x - a.x, y2 = c.y - a.y;
    48     return x1 * y2 != x2 * y1;
    49 }
    50 int main()
    51 {
    52     int n;
    53     int vis1[Max];
    54     while(scanf("%d",&n) != EOF)
    55     {
    56         if(!n)
    57             break;
    58         memset(vis, 0, sizeof(vis));
    59         memset(vis1, 0, sizeof(vis1));
    60         
    61         for(int i = 0; i < n; i++)
    62             if(!p[i].input())    // 处理重复的点
    63                 i--, n--;
    64         int st = 0; // 记录三角形个数
    65         for(int i = 0; i < n; i++)
    66         {
    67             for(int j = i + 1; j < n; j++)
    68             {
    69                 for(int k = j + 1; k < n; k++)
    70                 {
    71                     if(Isline(p[i], p[j], p[k]))
    72                         tri[st++].get_num(p[i],p[j],p[k]);
    73                 }
    74             }
    75         }
    76         
    77         int sum = 0, tep;
    78         for(int i = 0; i < st; i++)
    79         {
    80             if(!vis1[i]) // 没有访问过
    81             {
    82                 tep = 1;
    83                 vis1[i] = 1;
    84                 for(int j = i + 1; j < st; j++)
    85                     if(!vis1[j] && Issimi(tri[i], tri[j]))
    86                     {
    87                         tep++;
    88                         vis1[j] = 1;
    89                     }
    90                 if(tep > sum)
    91                     sum = tep;
    92             }
    93         }
    94         printf("%d
    ",sum);
    95     }
    96     return 0;
    97 }
    View Code
     
    生命不息,奋斗不止,这才叫青春,青春就是拥有热情相信未来。
  • 相关阅读:
    linux系统 ssh免密码登录服务器主机
    QPS TPS 并发数 响应时间
    mysqlmtop开源系统监控mysql数据库性能
    jenkins 自动化构建 部署 回滚配置
    实用Linux命令记录
    关于高并发的几个基础问题
    tcp四次挥手
    时序数据异常检测相关的问题记录
    判断时序数据的周期性
    最短路径问题
  • 原文地址:https://www.cnblogs.com/lyf-acm/p/5827178.html
Copyright © 2011-2022 走看看