Hou Yi's secret

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 38   Accepted Submission(s) : 6

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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个点,让你找出其中同一种相似三角形的数目的最大值

思路很简单,直接暴力就行了,可以算出每个三角形的角度,或者算边和边比值是否相等也可以。注意排除在一条直线上的点

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct node{__int64 x,y;
}p[30];
struct ege
{__int64 a,b,c;
}e[1000];
int vis[210][210];
int judge(__int64 a,__int64 b,__int64 a1,__int64 b1)
{//printf("%I64d%I64d %I64d %I64d\n",a,b,a1,b1);if(a*b1==b*a1)return 1;return 0;
}
int main()
{int i,j,k,n,m,maxx,num;while(scanf("%d",&n)!=EOF&&n){memset(vis,0,sizeof(vis));for(i=0,j=0;i<n;i++){scanf("%I64d%I64d",&p[j].x,&p[j].y);if(!vis[p[j].x+101][p[j].y+101]){vis[p[j].x+101][p[j].y+101]=1;j++;}}n=j;for(i=0,m=0;i<n-2;i++){for(j=i+1;j<n-1;j++){for(k=j+1;k<n;k++){if((p[i].y-p[k].y)*(p[i].x-p[j].x)==(p[i].x-p[k].x)*(p[i].y-p[j].y))continue;e[m].a=(p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y);//我保存的是边的平方e[m].b=(p[i].x-p[k].x)*(p[i].x-p[k].x)+(p[i].y-p[k].y)*(p[i].y-p[k].y);e[m++].c=(p[j].x-p[k].x)*(p[j].x-p[k].x)+(p[j].y-p[k].y)*(p[j].y-p[k].y);//printf("%I64d %I64d%I64d\n",e[m-1].a,e[m-1].b,e[m-1].c);}}}for(maxx=1,i=0;i<m-1;i++){for(num=1,j=i+1;j<m;j++){if((judge(e[i].a,e[i].b,e[j].a,e[j].b)&&judge(e[i].a,e[i].c,e[j].a,e[j].c))//这就是随机组合了,一共是六种情况||(judge(e[i].a,e[i].b,e[j].a,e[j].c)&&judge(e[i].a,e[i].c,e[j].a,e[j].b))||(judge(e[i].a,e[i].b,e[j].b,e[j].a)&&judge(e[i].a,e[i].c,e[j].b,e[j].c))||(judge(e[i].a,e[i].b,e[j].b,e[j].c)&&judge(e[i].a,e[i].c,e[j].b,e[j].a))||(judge(e[i].a,e[i].b,e[j].c,e[j].a)&&judge(e[i].a,e[i].c,e[j].c,e[j].b))||(judge(e[i].a,e[i].b,e[j].c,e[j].b)&&judge(e[i].a,e[i].c,e[j].c,e[j].a))){num++;//printf("%d %d%d \n",i,j,num);}}//printf("%d\n",num);if(maxx<num)maxx=num;}if(m==0)printf("0\n");elseprintf("%d\n",maxx);}return 0;
}

hdu4082 Hou Yi's secret(相似三角形)相关推荐

  1. HDU 4082 Hou Yi's secret

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082 题面: Hou Yi's secret Time Limit: 2000/1000 MS (Ja ...

  2. HDU - 4082 Hou Yi‘s secret (计算几何)

    点击打开题目链接 Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  3. HDU - 4082 Hou Yi's secret

    题意:求最多有多少的相似三角形 思路:枚举的情况下加上余弦定理,还有的就是要去重,相似的话,我们只要判断较小的两个角相等就行了,当然还要有精度的考虑 #include <iostream> ...

  4. HDU4082Hou Yi's secret(相似三角形的个数)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4082 题意: 给定n个点判断这些点能组成的三角形中,与同一个三角形相似的三角形的最大个数. 分析: ...

  5. HDU4082(相似三角形的个数)

    题目:Hou Yi's secret #include<stdio.h> #include<math.h> #include<map> #include<io ...

  6. 计算几何及其应用——计算几何基础

    写在前面:当时开计算几何这个专题神奇的从解析几何开始了,然后最近发现<计算几何及应用(金博)>这本书前面那章忽略掉了一些重要的东西比如说点定位.半平面相交之类的东西,恰好还有一些和计算几何 ...

  7. mvp 在 flutter 中的应用

    在 Android 应用程序开发过程中,我们经常会用到一些所谓的架构方法,如:mvp,mvvm,clean等.之所以这些方法会被推崇是因为他们可以大大的解耦我们的代码的功能模块,让我们的代码在项目中后 ...

  8. matlab模拟嫦娥奔月,2017年6月英语六级翻译模拟练习题:嫦娥奔月

    嫦娥奔月(chang'e Flying to the Moon)是中国古代的美丽传说.嫦娥是英雄人物后羿的妻子.在中国,嫦娥意味着月亮.源自对嫦娥的联想,中华民族对月亮有着特殊的情感,这甚至影响了中国 ...

  9. select语句的逻辑执行顺序,你知道吗?

    回顾一下上一篇博客说到的问题: mysql -uroot -ptest 我们不能赤裸裸的将账户和密码就这样写在你的脚本里,这并不是一个好做法.所有能够访问你脚本的人都会知道数据库的用户账户和密码.要解 ...

最新文章

  1. LeetCode 94. Binary Tree Inorder Traversal--二叉树中序遍历--递归,迭代--C++,Python解法
  2. 为什么运行了java文件老是404_哪位能帮助一下,JAVA中我运行页面时不能打开,总是出现404错误,为什么;用的是Tomcat7.0,win7的系统,...
  3. 如何让程序运行在所有CPU核心上
  4. 【git】【eclipse】记住密码/密码保存在哪里?
  5. [转载] 晓说——第9期:多如牛毛严酷无比的美国那些法
  6. 德国沃达丰成功商用4.5G 德国最快基站峰值速率达375Mbps
  7. MyISAM的key_buffer_size和InnoDB的innodb_buffer_pool_size
  8. java rsa2加密算法_java RSA加密解密
  9. 关于传奇MapInfo地图文件参数详细说明
  10. download.js实现下载的基本用法
  11. Unity 中从3D到Universal RP配置方法
  12. 利用vue.js实现一个砍价小程序
  13. typescript 中文手册
  14. 一款好看的 VSCode 代码主题和图标主题
  15. 7-4 华氏度转摄氏度 (5分) java
  16. 有赞测试新人训之探索与实践
  17. 企业考勤,用开源协同办公OA系统来管理!
  18. Android自定义广播和监听
  19. windows defender might impact performance
  20. 我也玩android了

热门文章

  1. Firefox常用扩展(extension)推荐
  2. Service 定义(startService、bindService、IntentService)
  3. FAQ02【Hive】:Hive连接后出现一堆乱七八糟的日志
  4. 软件设计师---数据库
  5. 简易爬取巨潮网年度审计报告
  6. 体系、创新――战略制定的两个关键词
  7. 虚拟内存与物理内存(滴水)
  8. Markdown出题模板(YZOJ-)
  9. 90后负债数据调查,人均负债超12万元
  10. 关于编码器8k超清,海图科技编码器的评估