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. window 下 Atom 侧边栏字体大小设置

    在 File 处找到 Settings 点击 找到 Themes 点击 找到 your stylesheet 点击 在 .tree-view 处设置即可, (按照 css 样式来写即可保存生效).

  2. String、StringBuffer与StringBuilder介绍

    关于这三个类在字符串处理中的位置不言而喻,那么他们到底有什么优缺点,到底什么时候该用谁呢?下面我们从以下几点说明一下 1.三者在执行速度方面的比较:     StringBuilder > St ...

  3. Java中高级面试题(1)

    List和Set比较,各自的子类比较 对比一:Arraylist与LinkedList的比较 1.ArrayList是实现了基于动态数组的数据结构,因为地址连续,一旦数据存储好了,查询操作效率会比较高 ...

  4. es之java操作插入文档

    4方式: . 使用json字符串直接创建 . 使用Map集合 . 使用第三方库来序列化 createDocumentBySerialize . 使用内置的帮助器XContentFactory.json ...

  5. 数据库为什么使用B+树而不是B树

    B树和B+树的区别主要有两点: 在B树中,你可以将键和值存放在内部节点和叶子节点,但在B+树中,内部节点都是键,没有值.叶子节点同时存放键和值 B+树的叶子节点有一条链相连,而B+树的叶子节点各自独立 ...

  6. Gradle 详解

    Gradle简单来说,就是工程的管理,帮我们做了依赖,打包,部署,发布等工作.就像一个管家管理我们的项目,我们只用关心写代码就可以了. 1 gradle-wraaper.properties 主工程的 ...

  7. fedora23深度配置gnome系统环境, 如设置ibus的面板字体大小 以及gedit 自动探测文件字符编码fileencodings

    除了系统桌面gnome, 以及gnome应用程序自带的preferences, 还有很多设置, 没有在preferences, 而是被深度地隐藏在系统中, 这时, 需要安装 dconf-tools: ...

  8. 【tensorflow使用笔记三】:tensorflow tutorial中的源码阅读

    https://blog.csdn.net/victoriaw/article/details/61195620#t0 input_data 没用的另一种解决方法:tensorflow1.8版本及以上 ...

  9. Jmeter响应中中文乱码怎么解决?

    在jmeter的bin目录下有一个jmeter.properties的文件,打开它,搜索sampleresult.default.encoding,把它的注释打开,也就是把最前面的#去掉,改成samp ...

  10. 002-es5.4.3结合spring-data-elasticsearch3.0.0.0使用

    一.使用前设置 1.elasticsearch开启 cmd下,进入安装目录 cd D:\developToool\elasticsearch-5.4.3 elasticsearch # 或者后台运行 ...