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. 3D Computer Grapihcs Using OpenGL - 12 Rotation Matrix

    为了证明我们上节渲染出来的是一个立方体而不是一个平面,我们决定将它旋转一定角度,这样我们就需要一个旋转矩阵(也属于ModelTransformMatrix的一部分) 上一节我们的ModelTransf ...

  2. va_list原理及用法

    最后更新:2017-02-22 这是一篇很早很早的博客文章,虽然很基础,但是毕竟曾经历程,因此也保存下来 1. 概念 va_list 是在C语言中定义的宏,指在解决 变参问题是指参数的个数不定,可以是 ...

  3. [CSP-S模拟测试]:小P的单调数列(树状数组+DP)

    题目描述 小$P$最近喜欢上了单调数列,他觉得单调的数列具有非常多优美的性质.经过小$P$复杂的数学推导,他计算出了一个单调增数列的艺术价值等于该数列中所有书的总和.并且以这个为基础,小$P$还可以求 ...

  4. angular6的响应式表单

    1:在AppModule模块里面引入 ReactiveFormsModule 要使用响应式表单,就要从@angular/forms包中导入ReactiveFormsModule,并把它添加到你的NgM ...

  5. 安装 windows 2008 解决 gpt 分区问题

    新服务器,4T硬盘,U盘安装Windows Server 2008 R2. 把2008的镜像用UltraISO写入U盘. 安装到分区那块,主分区200G,剩余分区系统自动给分为: 2T + 剩余 两块 ...

  6. python 浮点运算

    print(format(float(a)/float(b),'.2f'))

  7. curl_init raw传递json参数

    protected function curl_vm_record($url, $platform, $authorization, $jsonStr) { $ch = curl_init(); cu ...

  8. python nginx+uwsgi+WSGI 处理请求详解

    https://blog.csdn.net/a519640026/article/details/76157976 请求从 Nginx 到 uwsgi 到 django 交互概览 作为python w ...

  9. 001/Docker入门(Mooc)

    docker官网:https://www.docker.com/ 1.什么是docker 2.Docker思想     ==> [1].集装箱:保证程序完整(不缺东西,如配置文件等). [2]. ...

  10. python小感悟(初学者)

    计算机语言的起源: 在计算机刚发明出来的时候,是一大堆的机械硬件,然后技术人员开发了操作系统,操作系统是最底层的软件,负责与硬件沟通,执行其他软件的命令.由于计算机只能识别0和1两种特殊的机器语言,所 ...