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]的相似三角形有几个!!!
 
 #include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define eps 1e-10
#define oo 100000000
#define pi acos(-1)
struct point
{
double x,y;
point(double _x = 0.0,double _y = 0.0)
{
x =_x;
y =_y;
}
point operator -(const point &b)const
{
return point(x - b.x, y - b.y);
}
point operator +(const point &b)const
{
return point(x +b.x, y + b.y);
}
double operator ^(const point &b)const
{
return x*b.y - y*b.x;
}
double operator *(const point &b)const
{
return x*b.x + y*b.y;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
}; int dcmp(double a)
{
if(fabs(a)<eps)return ;
if(a>)return ;
else return -;
} bool operator ==(const point &a,const point &b)
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
} double dis(point a,point b)
{
return sqrt((a-b)*(a-b));
} double len(point a)
{
return sqrt(a*a);
} double Angle(point a,point b)
{
double ans=acos((a*b)/len(a)/len(b));
return ans;
} bool cmp(point a,point b)
{
if(dcmp(a.x-b.x)==)return a.y<b.y;
return a.x<b.x;
} double jiao[];
int dp[][];
point P[],p[];
int main()
{ int n,i,j,k;
while(~scanf("%d",&n)&&n)
{
for(i=;i<n;i++) P[i].input();
int ss=;
sort(P,P+n,cmp);
p[]=P[];
for(i=;i<n;i++)//排除重复的点!!
{
if(p[ss-]==P[i])
continue;
p[ss++]=P[i];
}
n=ss;
int cnt=;
for(i=;i<n;i++)
for(j=;j<n;j++)
for(k=;k<n;k++)
{
if(i!=j&&i!=k&&j!=k)
{
point v,w;
v=p[j]-p[i];
w=p[k]-p[i];
double ag=Angle(v,w);
if(dcmp(ag)>)
jiao[cnt++]=ag;
}
}
sort(jiao,jiao+cnt);
cnt=unique(jiao,jiao+cnt)-jiao;
for(i=;i<=cnt;i++)
for(j=;j<=cnt;j++)
dp[i][j]=;
for(i=;i<n;i++)
for(j=i+;j<n;j++)
for(k=j+;k<n;k++)
{
point v,w;
double ag1,ag2,ag3;
v=p[j]-p[i];
w=p[k]-p[i];
if(dcmp(v^w)==)continue;//排除共线情况,否则wa!!
ag1=Angle(v,w);
v=p[i]-p[j];
w=p[k]-p[j];
ag2=Angle(v,w);
v=p[i]-p[k];
w=p[j]-p[k];
ag3=Angle(v,w);
double aa[];
aa[]=ag1;aa[]=ag2;aa[]=ag3;
sort(aa,aa+);
int ii,jj;
for(int kk=;kk<cnt;kk++)
{
if(dcmp(aa[]-jiao[kk])==)ii=kk;
if(dcmp(aa[]-jiao[kk])==){jj=kk;break;}
}
dp[ii][jj]++;
}
int ans=;
for(i=;i<cnt;i++)
for(j=i;j<cnt;j++)
if(dcmp(jiao[i])!=)
ans=max(ans,dp[i][j]);
printf("%d\n",ans);
}
return ;
}

最新文章

  1. Oracle启动报错ORA-03113解决
  2. MySQL DCL 整理
  3. mongodb字段类型转化
  4. [ubuntu] adb devices出现no permissions
  5. 爱春秋之戏说春秋 Writeup
  6. 回忆一次面试Android研发的问题
  7. 3分钟wamp中php安装 pear 然而并没有用 并没能借此安装phpunit 不得不借用了其他的方式安装phpunit
  8. php输出csv文件 简单实现
  9. careercup-高等难度 18.6
  10. Xcode中Info.plist文件各个键的作用说明【搜藏】
  11. Winodws安装系统时,通过安装磁盘进行分区
  12. Codevs 4560 NOIP2015 D2T2 子串
  13. Qt学习之路(1)------Qt常用类用法说明
  14. 关于HttpServlet和Servlet以及doPost和doGet关系
  15. java中获取类加载路径和项目根路径的5种方法
  16. Python 引用、浅拷贝、深拷贝解析
  17. Git相关操作二
  18. sourceTree每次拉取代码和提交代码都需要输入密码
  19. cxf 整合 spring 时 java.lang.VerifyError异常
  20. iOS 多线程 NSOperation、NSOperationQueue

热门文章

  1. es之关于consistency(数据一致性问题)
  2. 《SQL Server 2012 T-SQL基础》读书笔记 - 4.子查询
  3. fengmiantu3
  4. Anyhashable打印格式化
  5. BBED ORA-00600: internal error code, arguments: [16703], [1403], [20], [], [], [], [], [], [], [], [], []
  6. WeakHashMap 源码分析
  7. C#和.NET获取绝对路径
  8. java将url里面的中文改成ASCII字符集 和 SCII字符集 改成 中文
  9. 树的基本概念以及java实现二叉树
  10. Pandas 50题练习