HDU 4082 Hou Yi's secret 暴力枚举
2013-08-07 21:55
417 查看
Hou Yi's secret
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1898 Accepted Submission(s): 456
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
题意:n个点的坐标,求他们连成的正方形中最多有多少个相似的。
思路:直接暴力,将三角形每个角的余弦作为该三角形的标识即可
注意:如果连不成三角形则答案为0。
AC代码;
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; #define eps 1e-8 struct Point { int x, y; } dian[20]; struct Tri { double angle[3]; } sjx[8005]; template<class A> inline A Fx(A x) { return x * x; } inline double Dist(Point a, Point b) { return sqrt(1.0 * Fx(a.x - b.x) + 1.0 * Fx(a.y - b.y)); } inline int Dcmp(double x) { if (fabs(x) < eps) return 0; else if (x < 0) return -1; return 1; } inline bool Jude(double a, double b, double c) { if (Dcmp(a + b - c) <= 0) return false; else if (Dcmp(a + c - b) <= 0) return false; else if (Dcmp(b + c - a) <= 0) return false; else return true; }//判断能否组成三角形 inline double Getangle(double a, double b, double c) { return (Fx(a) + Fx(b) - Fx(c)) / (2.0 * a * b); }//求出每个角的余弦,不需要用acos求真正的角度了 bool Sim(Tri a, Tri b) { for (int i = 0; i < 2; ++i) if (Dcmp(a.angle[i] - b.angle[i]) != 0) return false; return true; }//判断两个三角形是否相似,只需判断两个角即可。 bool vis[205][205]; int main(int argc, char **argv) { int n; while (scanf("%d", &n), n) { int x, y; memset(vis, 0, sizeof(vis)); int cur = 0; for (int i = 0; i < n; ++i) { scanf("%d%d", &x, &y); if (vis[x + 100][y + 100] == false) {//判重 dian[cur].x = x; dian[cur].y = y; vis[x + 100][y + 100] = true; cur++; } } int cnt = 0; for (int i = 0; i < cur; ++i) { for (int j = i + 1; j < cur; ++j) { for (int k = j + 1; k < cur; ++k) { double a = Dist(dian[i], dian[j]); double b = Dist(dian[j], dian[k]); double c = Dist(dian[i], dian[k]); if (Jude(a, b, c)) { sjx[cnt].angle[0] = Getangle(a, b, c); sjx[cnt].angle[1] = Getangle(a, c, b); sjx[cnt].angle[2] = Getangle(b, c, a); sort(sjx[cnt].angle, sjx[cnt].angle + 3); cnt++; } } } } int res = 0;//如果一个三角形都组不成,那么答案就是0 for (int i = 0; i < cnt; ++i) { int ans = 0; for (int j = i; j < cnt; ++j) { if (Sim(sjx[i], sjx[j])) ans++; } res = max(res, ans); } printf("%d\n", res); } return 0; }
相关文章推荐
- HDU 4082 Hou Yi's secret 伪相似三角形 && 2011 Asia Beijing Regional Contest
- hdu 4082 Hou Yi's secret 统计相似三角形 暴力
- HDU 4082 Hou Yi&#39;s secret --枚举
- hdu&nbsp;4082&nbsp;Hou&nbsp;Yi&#039;s&nbsp;secret&nbsp;枚举
- 【几何】2011 regional Beijing Site B——Hou Yi's secret——hdu 4082
- Hou Yi's secret(hdu4082——2011icpc北京站B题)
- HDU 4082 Hou Yi's secret
- 杭电 hdu 5616 Jam's balance【思维】【暴力枚举】
- HDU 4082 Hou Yi's secret
- HDU 4082 Hou Yi's secret(相似三角形最大数量)
- HDU 4082 Hou Yi's secret
- HDU - 4082 Hou Yi's secret
- HDU 4082 Hou Yi's secret-求相似三角形的最大个数-(坑货)
- hdu 4082 Hou Yi's secret
- HDU 4082 Hou Yi's secret
- HDU 4430 Yukari's Birthday 枚举+二分
- hdu 4932 Miaomiao's Geometry 暴力枚举
- HDU-4932-Miaomiao's Geometry【暴力枚举】
- HDU 5616 Jam's balance(暴力枚举子集)
- HDU 4082 Hou Yi's secret (几何,求相似三角形个数,暴力枚举,map记录)