`

hdu 4082 Hou Yi's secret(亚洲赛北京赛区B题)

阅读更多

Hou Yi's secret

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

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
 

        阴险的水题,提交第16次才AC,最后一个小时里AC了,当时差点崩溃。

        注意:数组大小要开大点,重复点算一个,组成不能三角形就不用判断了。

        当场阴死了很多队伍,清华、交大都WA差不多10次,以后做题要读清题目意思!

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082

代码:

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <memory.h>
#include <algorithm>
using namespace std;

const double eps = 1e-6;

struct point
{
    int x, y;
    bool tar;   //tar是标记重复的点
}p[25];     //点数很少,可以暴力

struct triangle
{
    double ang[3];
}t[8005];   //20*20*20 = 8000,不要开小了

double dis(point a, point b)    //求两点的距离
{
    return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

bool judge(double a, double b, double c)    //判断是否三点能否组成三角形
{
    if(a + b <= c) return false;
    if(a + c <= b) return false;
    if(b + c <= a) return false;
    return true;
}

bool ok(triangle a, triangle b)     //判断两个三角形是否相似,两个角相等就行
{
    if( fabs(a.ang[0] - b.ang[0]) < eps && fabs(a.ang[1] - b.ang[1]) < eps ) return true;
    return false;
}

bool hash[205][205], flag[8005];

int main()
{
    int i, j, k, n, sum, tx, ty, temp, MAX;
    double a, b, c;
    while(scanf("%d", &n), n)
    {
        for(i = 0; i < n; i++) p[i].tar = false;
        memset(hash, false, sizeof(hash));
        for(i = 0; i < n; i++)
        {
            scanf("%d %d", &p[i].x, &p[i].y);
            tx = p[i].x + 100;
            ty = p[i].y + 100;
            if(hash[tx][ty] == false)   //hash判断是否有重复点
            {
                hash[tx][ty] = true;
                p[i].tar = true;
            }
        }
        sum = 0;
        for(i = 0; i < n; i++)
        {
            if(!p[i].tar) continue;
            for(j = i + 1; j < n; j++)
            {
                if(!p[j].tar) continue;
                for(k = j + 1; k < n; k++)
                {
                    if(!p[k].tar) continue;
                    a = dis(p[i], p[j]);
                    b = dis(p[j], p[k]);
                    c = dis(p[i], p[k]);
                    if(judge(a, b, c))  //3边能组成三角形
                    {
                        //余弦定理求三角形的三个角
                        t[sum].ang[0] = acos((b*b+c*c-a*a)/(2*b*c));
                        t[sum].ang[1] = acos((a*a+c*c-b*b)/(2*a*c));
                        t[sum].ang[2] = acos((b*b+a*a-c*c)/(2*b*a));
                        sort(t[sum].ang, t[sum].ang + 3);
                        sum++;
                    }
                }
            }
        }
        memset(flag, false, sizeof(flag));
        MAX = 0;
        for(i = 0; i < sum; i++)    //开始求最大值
        {
            if(flag[i]) continue;
            flag[i] = true;
            temp = 0;
            for(j = i; j < sum; j++)
            {
                if(ok(t[i], t[j]))
                {
                    flag[j] = true;
                    temp++;
                    if(temp > MAX) MAX = temp;
                }
            }
        }
        printf("%d\n", MAX);
    }

    return 0;
}

 

 

 

 

0
1
分享到:
评论

相关推荐

    hdu.rar_HDU 1089.cpp_OJ题求和_hdu_horsekw5_杭电obj

    【标题】"hdu.rar_HDU 1089.cpp_OJ题求和_hdu_horsekw5_杭电obj" 提供的信息是关于一个压缩文件,其中包含了一个名为 "HDU 1089.cpp" 的源代码文件,这个文件是为了解决杭州电子科技大学(Hangzhou Dianzi ...

    hdu.rar_hdu

    HDU(杭州电子科技大学在线评测系统)是一个深受程序员喜爱的在线编程练习平台,它提供了丰富的算法题目供用户挑战,帮助他们提升编程技能和算法理解能力。"hdu.rar_hdu"这个压缩包文件很可能是某位程序员整理的他在...

    ACM HDU题目分类

    ACM HDU 题目分类是指对 HDU 在线判题系统中题目的分类,总结了大约十来个分类。这些分类将有助于编程选手更好地理解和解决问题。 DP 问题 DP(Dynamic Programming,动态规划)是一种非常重要的算法思想,在 ACM ...

    离线OJ题库(HDU ZJU等,部分有答案)

    离线OJ题库是为编程爱好者和程序员提供的一种便捷的学习资源,主要包含来自不同在线判题系统(如HDU - 浙江大学多模式在线评测系统,ZJU - 浙江大学在线评测系统等)的编程题目。这类题库通常包含多种编程语言的题目...

    杭电HDU2050题的ac程序

    一个十分简单的程序,能够ac杭电hdu的第2050题,无注释,简单明了

    HDU_2010.rar_hdu 2010_hdu 20_hdu acm20

    "hdu"可能是指杭州电子科技大学(Hangzhou Dianzi University),这所学校经常举办ACM编程竞赛,并有自己的在线判题系统——HDU Online Judge,供参赛者提交代码并测试解决方案。 【压缩包子文件的文件名称列表】中...

    HDU.rar_hdu_hdu07_com_shownv9b_www.563hdu.

    【描述】"HDU一部分题目原码,大部分是可运行的,可能有几题不完整" 表明这个压缩包中的内容主要是HDU平台上一些编程题目的解决方案,源代码文件。这些代码大部分是可以直接运行的,意味着它们已经实现了题目所要求...

    HDU题目java实现

    【标题】"HDU题目java实现"所涉及的知识点主要集中在使用Java编程语言解决杭州电子科技大学(HDU)在线评测系统中的算法问题。HDU是一个知名的在线编程竞赛平台,它提供了大量的算法题目供参赛者练习和提交解决方案...

    hdu1250高精度加法

    ### hdu1250高精度加法 #### 背景介绍 在计算机科学与编程竞赛中,处理大整数运算(特别是加法、减法、乘法等)是常见的需求之一。当数字的位数超过了标准数据类型(如`int`、`long`等)所能表示的最大值时,就需要...

    HDU DP动态规划

    【描述】提到的"HDU的一题"可能是指HDU(杭州电子科技大学)在线判题系统中的一道动态规划题目。这个系统经常被用来举办各类编程竞赛,包括ACM/ICPC(国际大学生程序设计竞赛)等。描述中的省略部分可能包含了具体...

    acm课件简单数学题(杭电)(HDU)

    本课件"acm课件简单数学题(杭电)(HDU)"正是针对这一领域的一份宝贵资源,旨在提升参赛者解决数学问题的能力,从而在ACM竞赛中提高AC(Accepted,即正确解答)题目的效率。 课件中包含的“简单数学题090223.ppt...

    ACM HDU

    【ACM HDU】指的是在ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest)中,参赛者在杭州电子科技大学(Hangzhou Dianzi University,简称HDU)的在线评测系统上完成并已解决的题目集合...

    POJ、HDU、ZOJ、SOJ水题过滤器

    标题中的“POJ、HDU、ZOJ、SOJ水题过滤器”指的是一个工具,它主要用于帮助在ACM(国际大学生程序设计竞赛)训练中筛选出这些在线判题系统中的简单题目,即所谓的“水题”。这些在线判题平台是编程爱好者和参赛者们...

    HDU acm-PPT课件

    【ACM入门与提高:HDU ACM竞赛课程详解】 ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest,简称ICPC或ACM/ICPC)是一项全球性的竞赛,旨在激发大学生对计算机科学的兴趣,提升他们的...

    HDU1059的代码

    HDU1059的代码

    hdu1001解题报告

    hdu1001解题报告

    hdu 1574 passed sorce

    hdu 1574 passed sorce

    HDU题库.zip

    HDU题库.zip是一个压缩包文件,包含了从1000到6543号的所有HDU(杭州电子科技大学在线编程平台,也被称为HDU Online Judge)编程竞赛题目。这个资源对于学习算法、提高编程技能以及准备各类编程竞赛的用户来说极其...

    100道 acm C语言 hdu 解题报告

    100道 acm C语言 hdu 解题报告

Global site tag (gtag.js) - Google Analytics