点击打开题目链接

Hou Yi's secret

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

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
Source
2011 Asia Beijing Regional Contest
Recommend
lcy   |   We have carefully selected several similar problems for you:  4081 4085 4089 4090 4087 

Statistic | Submit | Discuss | Note

题目大意:给出n个点,连接成三角形,求与某个三角形相似的三角形的最大个数。

思路:遍历所有的点,如果三个点能构造成三角形则放入vector数组里,然后遍历vector数组求最大解。

比赛时WA了5发才A掉,看似简单但AC率极低的一个题。主要坑点有两个。

①判断是否可以构成三角形,只判断两边之和大于第三边是不够的,因为可能有平行的情况,但是判断斜率的话又太麻烦,还有考虑斜率不存在。所以可以直接用向量法判平行,然后判断两边之和大于三边。

②点可以重复。所以要先进行去重,用了set。

今天跟队友学到很多,发现了很多自己的不足。比如我做题太心急,WA掉多次之后就没办法整理出新的思路,还有就是代码没注释没空格,不方便维护检查程序。另外做题要认真读题意,不能先入为主想当然的做。

附上AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>using namespace std;
set<pair<double , double> >s;
int _max,ans;
int flag=1;struct tris{double x,y;
}tri[30];struct angle{double a1,a2,a3;
};
vector<angle>v;
int main(){int n;while(~scanf("%d",&n)&&n!=0){v.clear();s.clear();for(int i=1;i<=n;i++){double t1,t2;scanf("%lf%lf",&t1,&t2);pair<double ,double >p;p.first=t1;p.second=t2;s.insert(p);}int cnt=1;for(set<pair<double,double> >::iterator it=s.begin();it!=s.end();it++){tri[cnt].x=it->first;tri[cnt++].y=it->second;}for(int i=1;i<cnt;i++){for(int j=i+1;j<cnt;j++){for(int k=j+1;k<cnt;k++){//求三角形三边double n1,n2,n3;double sum1=0.00;n1=sqrt((tri[i].x-tri[j].x)*(tri[i].x-tri[j].x) + (tri[i].y-tri[j].y)*(tri[i].y-tri[j].y));n2=sqrt((tri[i].x-tri[k].x)*(tri[i].x-tri[k].x) + (tri[i].y-tri[k].y)*(tri[i].y-tri[k].y));n3=sqrt((tri[k].x-tri[j].x)*(tri[k].x-tri[j].x) + (tri[k].y-tri[j].y)*(tri[k].y-tri[j].y));//边排序sum1=n1+n2+n3;n1=min(n1,min(n2,n3));n3=max(n1,max(n2,n3));n2=sum1-n1-n3;//三个向量double x1,y1,x2,y2,x3,y3;x1=tri[i].x-tri[j].x;y1=tri[i].y-tri[j].y;x2=tri[j].x-tri[k].x;y2=tri[j].y-tri[k].y;x3=tri[i].x-tri[k].x;y3=tri[i].y-tri[k].y;//判断向量平行double k1=(x1*y2)-(x2*y1);double k2=(x2*y3)-(x3*y2);double k3=(x1*y3)-(x3*y1);if(fabs(k1)<=1e-9||fabs(k2)<=1e-9||fabs(k3)<=1e-9)continue;if(n1+n2-n3<=1e-9)continue;//求三角形三角的cos值angle tmp;tmp.a1=(n2*n2+n3*n3-n1*n1)/(2.0*n2*n3);tmp.a2=(n1*n1+n3*n3-n2*n2)/(2.0*n1*n3);tmp.a3=(n1*n1+n2*n2-n3*n3)/(2.0*n1*n2);//排序double sum=tmp.a1+tmp.a2+tmp.a3;tmp.a1=min(tmp.a1,min(tmp.a2,tmp.a3));tmp.a3=max(tmp.a1,max(tmp.a2,tmp.a3));tmp.a2=sum-tmp.a1-tmp.a3;v.push_back(tmp);}flag=1;if(v.size()==0)flag=0;_max=0,ans=0;for(int i=0;i<v.size();i++){for(int j=0;j<v.size();j++){if(fabs(v[i].a1-v[j].a1)<=1e-9 && fabs(v[i].a2-v[j].a2)<=1e-9 && fabs(v[i].a3-v[j].a3)<=1e-9){_max++;}}ans=max(_max,ans);_max=0;}}}if(flag==0)printf("0\n");elseprintf("%d\n",ans);}return 0;
}

HDU - 4082 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

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

  3. hdu4082 Hou Yi's secret(相似三角形)

    Hou Yi's secret Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tot ...

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

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

  5. hdu 4793(嗷嗷水的计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4793: 大意:在原点有一个平台,原点还有一个圆形木块,视为挡板,有一个圆形滑块在光滑坐标轴上摩擦,有初 ...

  6. hdu 4562 守护雅典娜(计算几何+dp)

    守护雅典娜 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Subm ...

  7. HDU 3968 Angry Birds Again(计算几何)

    Description 给出小鸟的位置以及猪的位置,小鸟做斜抛运动经过ts后砸到猪,问小鸟经过的路程 Input 第一行为一整数T表示你用例组数,每组用例包括四个浮点数x0,y0,x1,y1,t分别表 ...

  8. HDU 4741 Save Labman No.004 计算几何 数学

    题目链接 这道题会暴露很多孩纸的高数学的好不好.如何计算三维直线的最短距离和垂足的坐标,学习链接 之后的就是代入公式计算了. 1 #include <stdio.h> 2 #include ...

  9. HDU 4741 Save Labman No.004(计算几何)

    题目链接 抄的模版...mark一下. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> ...

最新文章

  1. #翻译NO.4# --- Spring Integration Framework
  2. Windows10文件重命名/复制/移动时,导致文件资源管理器卡顿,解决方案
  3. Hello Blazor:(6)你必须踩过这5个坑,才算学会部署Blazor WebAssembly到静态网站
  4. java代码耗尽内存_有关Java内存溢出及内存消耗的小知识
  5. Django 和 html
  6. 12306 抢票项目霸榜 GitHub,标星即将破万
  7. 【例1】 0/1背包《信息学奥赛一本通》【解法一】 02
  8. 1,2,3……,9组成3个三位数abc,def和ghi,每个数字恰好使用一次,要求abc:def:ghi=1:2:3.输出所有解。
  9. python向自己qq邮箱发信息_python 向qq邮箱发邮件
  10. [转载] Python中协程的详细用法和例子
  11. cad文字宽度因子_为什么CAD中无法修改文字的宽度比例?
  12. 串口、Modbus通信协议
  13. vector扩容时以2倍或1.5倍扩容的原因
  14. 标准差(standard deviation)
  15. SSL构建单双向https认证
  16. ug998逻辑思维导图
  17. [深入理解Android卷二 全文-第四章]深入理解PackageManagerService
  18. win101809最新专业版企业版激活密钥和功能
  19. 大学计算机实验教程制作电子小报,word使用教程:制作电子小报
  20. 郊区春游 (状压dp)

热门文章

  1. 【软件质量保证与测试】实验一、基于Selenium+Python的自动化测试
  2. 基于PHP的视频社交管理系统
  3. NLP.TM[36] | NLP之源:n-gram语言模型
  4. 基于proe的阀体零件的机械加工工艺及夹具设计
  5. 【操作系统】虚拟地址和页表项的关系
  6. QT读书笔记—绘图基础
  7. [ 2204听力 ] 三
  8. lego-loam数据_使用lego minifigures数据集在fastai中对datablocks api图像进行分类
  9. SpringCloud 实战笔记
  10. 在软件工程领域,搞科研的这十年!