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 ;
}

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. 170830-关于JdbcTemplate的知识点

    1.Spring提供的一个操作数据库的技术JdbcTemplate,是对Jdbc的封装.语法风格非常接近DBUtils. JdbcTemplate可以直接操作数据库,加快效率,而且学这个JdbcTem ...

  2. java的基本数据类型有

    整型数据根据它所占内容大小的不同可分为4种类型. 数据类型 内存 byte 8位 short 16位 int 32位 long 64位 浮点类型 数据类型 内存 float 32位 double 64 ...

  3. win7 注册删除postgresql服务

    注册服务 删除服务 备注:都以管理员身份运行dos

  4. 史上最详细的XGBoost实战

    史上最详细的XGBoost实战 0. 环境介绍 Python 版 本: 3.6.2 操作系统 : Windows 集成开发环境: PyCharm 1. 安装Python环境 安装Python 首先,我 ...

  5. PowerDesigner相关总结

    1.PowerDesigner 工具生成数据库Report指导 摘自:https://www.cnblogs.com/zycblog/archive/2010/05/11/1732918.html 1 ...

  6. 二进制安装MySQL5.6 MySQL5.7

    1:系统版本 [root@vhost1 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.5 (Santiag ...

  7. python异常处理(try-except)

    什么是异常? 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在Python无法正常处理程序时就会发生一个异常. 异常是Python对象,表示一个错误. 当Pyth ...

  8. 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第1节 Scanner类_5-练习二_键盘输入三个数字

    思路分析: 获取前两个数字中的看最大值,有多重写法,这里先演示第一种.三元运算符的方式  

  9. 测开之路一百零七:bootstrap排版

    引入bootstrap和jquery 标题 对齐 正文强调 引言 <!DOCTYPE html><html lang="en"><head> & ...

  10. Leaflet

    https://leafletjs.com/ https://github.com/Leaflet/Leaflet