Hou Yi's secret

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

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
 
 
题意:给你n个点,问最多有多少三角形相似!
 
暴力枚举!刚开始忘记去重了,否则三角形会重复算的!!!
 
dp[i][j]为最小的两个角为jiao[i]和jiao[j]的相似三角形有几个!!!
 
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<algorithm>
  4. using namespace std;
  5. #define eps 1e-10
  6. #define oo 100000000
  7. #define pi acos(-1)
  8. struct point
  9. {
  10. double x,y;
  11. point(double _x = 0.0,double _y = 0.0)
  12. {
  13. x =_x;
  14. y =_y;
  15. }
  16. point operator -(const point &b)const
  17. {
  18. return point(x - b.x, y - b.y);
  19. }
  20. point operator +(const point &b)const
  21. {
  22. return point(x +b.x, y + b.y);
  23. }
  24. double operator ^(const point &b)const
  25. {
  26. return x*b.y - y*b.x;
  27. }
  28. double operator *(const point &b)const
  29. {
  30. return x*b.x + y*b.y;
  31. }
  32. void input()
  33. {
  34. scanf("%lf%lf",&x,&y);
  35. }
  36. };
  37.  
  38. int dcmp(double a)
  39. {
  40. if(fabs(a)<eps)return ;
  41. if(a>)return ;
  42. else return -;
  43. }
  44.  
  45. bool operator ==(const point &a,const point &b)
  46. {
  47. return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
  48. }
  49.  
  50. double dis(point a,point b)
  51. {
  52. return sqrt((a-b)*(a-b));
  53. }
  54.  
  55. double len(point a)
  56. {
  57. return sqrt(a*a);
  58. }
  59.  
  60. double Angle(point a,point b)
  61. {
  62. double ans=acos((a*b)/len(a)/len(b));
  63. return ans;
  64. }
  65.  
  66. bool cmp(point a,point b)
  67. {
  68. if(dcmp(a.x-b.x)==)return a.y<b.y;
  69. return a.x<b.x;
  70. }
  71.  
  72. double jiao[];
  73. int dp[][];
  74. point P[],p[];
  75. int main()
  76. {
  77.  
  78. int n,i,j,k;
  79. while(~scanf("%d",&n)&&n)
  80. {
  81. for(i=;i<n;i++) P[i].input();
  82. int ss=;
  83. sort(P,P+n,cmp);
  84. p[]=P[];
  85. for(i=;i<n;i++)//排除重复的点!!
  86. {
  87. if(p[ss-]==P[i])
  88. continue;
  89. p[ss++]=P[i];
  90. }
  91. n=ss;
  92. int cnt=;
  93. for(i=;i<n;i++)
  94. for(j=;j<n;j++)
  95. for(k=;k<n;k++)
  96. {
  97. if(i!=j&&i!=k&&j!=k)
  98. {
  99. point v,w;
  100. v=p[j]-p[i];
  101. w=p[k]-p[i];
  102. double ag=Angle(v,w);
  103. if(dcmp(ag)>)
  104. jiao[cnt++]=ag;
  105. }
  106. }
  107. sort(jiao,jiao+cnt);
  108. cnt=unique(jiao,jiao+cnt)-jiao;
  109. for(i=;i<=cnt;i++)
  110. for(j=;j<=cnt;j++)
  111. dp[i][j]=;
  112. for(i=;i<n;i++)
  113. for(j=i+;j<n;j++)
  114. for(k=j+;k<n;k++)
  115. {
  116. point v,w;
  117. double ag1,ag2,ag3;
  118. v=p[j]-p[i];
  119. w=p[k]-p[i];
  120. if(dcmp(v^w)==)continue;//排除共线情况,否则wa!!
  121. ag1=Angle(v,w);
  122. v=p[i]-p[j];
  123. w=p[k]-p[j];
  124. ag2=Angle(v,w);
  125. v=p[i]-p[k];
  126. w=p[j]-p[k];
  127. ag3=Angle(v,w);
  128. double aa[];
  129. aa[]=ag1;aa[]=ag2;aa[]=ag3;
  130. sort(aa,aa+);
  131. int ii,jj;
  132. for(int kk=;kk<cnt;kk++)
  133. {
  134. if(dcmp(aa[]-jiao[kk])==)ii=kk;
  135. if(dcmp(aa[]-jiao[kk])==){jj=kk;break;}
  136. }
  137. dp[ii][jj]++;
  138. }
  139. int ans=;
  140. for(i=;i<cnt;i++)
  141. for(j=i;j<cnt;j++)
  142. if(dcmp(jiao[i])!=)
  143. ans=max(ans,dp[i][j]);
  144. printf("%d\n",ans);
  145. }
  146. return ;
  147. }

hdu 4082 Hou Yi's secret(暴力枚举)的更多相关文章

  1. HDU 4082 Hou Yi's secret --枚举

    题意: 给n个点,问最多有多少个相似三角形(三个角对应相等). 解法: O(n^3)枚举点,形成三角形,然后记录三个角,最后按三个角度依次排个序,算一下最多有多少个连续相等的三元组就可以了. 注意:在 ...

  2. HDU 4082 Hou Yi's secret(暴力)

    直接6重循环就行了吧...判三角形相似直接从小到大枚举两向量夹角是否相等就行了.注意去重点跟三点共线就行了... #include<algorithm> #include<iostr ...

  3. [HDU 4082] Hou Yi's secret (简单计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082 题目大意: 给你n个点,问能最多构成多少个相似三角形. 用余弦定理,计算三个角度,然后暴力数有多 ...

  4. HDU - 4082 Hou Yi's secret

    题意:射箭落在n个点,任取三点可构成一个三角形,问最大的相似三角形集(一组互相相似的三角形)的个数. 分析: 1.若n个点中有相同的点,要去重,题目中说射箭会形成洞,任选三个洞构成三角形,因此射在同一 ...

  5. HDU - 1248 寒冰王座 数学or暴力枚举

    思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...

  6. HDU 5944 Fxx and string(暴力/枚举)

    传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Othe ...

  7. hdu 4968 Improving the GPA (水 暴力枚举)

    题目链接 题意:给平均成绩和科目数,求可能的最大学分和最小学分. 分析: 枚举一下,可以达到复杂度可以达到10^4,我下面的代码是10^5,可以把最后一个循环撤掉. 刚开始以为枚举档次的话是5^10, ...

  8. HDU 5660 jrMz and angles (暴力枚举)

    jrMz and angles 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/E Description jrMz has tw ...

  9. hdu 5595 GTW likes math(暴力枚举查询)

    思路:直接暴力枚举区间[l,r]的整数值,然后max和min就可以了. AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000 ...

随机推荐

  1. MySQL Password Expired

    好久没有登录MySQL,登录的时候遇到如下提示: 尝试使用命令行登录,发现是可以使用之前的密码登录的,如下: 只是登录之后,发现做不了什么操作.并且使用,alter 语句重设密码也没有成功,如下: 试 ...

  2. Visual Studio2015 community 许可证到期问题

    申请微软账户直接登录可以继续使用.

  3. axios的详细用法以及后端接口代理

    安装 使用 npm: $ npm install axios 或者 使用 bower: $ bower install axios 或者直接使用 cdn: <script src="h ...

  4. 002-localStorage和sessionStorage操作

    一.概述 HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 一直存在除非用户手动清除缓存;是基于域的,任何该域下的所有页面都可访问localSto ...

  5. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_09 序列化流_2_对象的序列化流_ObjectOutputStream

    创建person对象.生成构造方法全参和无参.getter和setter 抛出异常:没有序列化异常 接口的源码 啥都没有.就起到一个标记的作用 用二进制存的

  6. IDEA开发环境设置

    IDEA开发环境设置 1.关闭自动更新 IntelliJ IDEA默认会自动进行版本的更新,在网络异常时经常会导致各种各样的问题,因此强烈建议关闭自动更新. File->Settings 2.隐 ...

  7. NoSQL基础学习

    NoSQL基础学习 最近学习的第一个Nosql就是Mongodb,为了了解Nosql的基本知识,特地总结,主要是学习Nosql的理论 一.Introduction(介绍) 它是“ Not Only S ...

  8. mysql忘记密码/修改密码

    关键词:忘记密码,修改密码,mysql忘记密码,mysql修改密码 转自:https://www.cnblogs.com/jdxn/p/6847089.html 方法1: 用SET PASSWORD命 ...

  9. Maven构建Struts2框架的注意事项

    [本人出错点:404,就是在web.xml配置文件中少配置了struts.xml的路径] 1.创建Maven,搭建Struts框架,实现最基本的Hello World 在pom.xml中加入strut ...

  10. Ant-编译构建(1)-HelloWorld

    1.项目目录构成,lib包暂时为空,本次例子未引入第三方包. 2.编写相关的build.xml <?xml version="1.0" encoding="utf- ...