hdu4082 Hou Yi's secret 暴力

http://acm.hdu.edu.cn/showproblem.php?pid=4082

Hou Yi‘s secret

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3006    Accepted Submission(s): 710

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

2011 Asia Beijing Regional Contest

题意:给最多18个点,问最多有多少个相似的三角形。

分析:18个点。。就枚举所有可以组成的三角形判断相似就好。。注意要判断重点和平行的情况。。

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
const double eps=1e-8;
const double pi=acos(-1.0);
const int INF=0x7fffffff;
const LL inf=(((LL)1)<<61)+5;
bool vis[250][250];
struct point{
    double x,y;
    point(double x=0,double y=0):x(x),y(y) {}
}a[22];
struct triangle{
    double x,y,z;
}b[18*18*18];
bool gao(int i,int j)
{
    if(fabs(b[i].x*b[j].y-b[i].y*b[j].x)<eps&&fabs(b[i].z*b[j].y-b[i].y*b[j].z)<eps)
        return true;
    return false;
}
bool check(int i,int j,int k)
{
    point p1=point(a[i].x-a[j].x,a[i].y-a[j].y);
    point p2=point(a[k].x-a[j].x,a[k].y-a[j].y);
    return fabs(p1.x*p2.y-p1.y*p2.x)<eps;
}
double dis(int i,int j)
{
    return sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
}
int main()
{
    int n,m;
    while(~scanf("%d",&m)&&m)
    {
        clr(vis);
        n=0;
        for(int i=0;i<m;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            if(!vis[x+100][y+100])
            {
                vis[x+100][y+100]=true;
                a[n].x=x;
                a[n++].y=y;
            }
        }
        m=0;
        for(int i=0;i<n-2;i++)
        {
            for(int j=i+1;j<n-1;j++)
            {
                for(int k=j+1;k<n;k++)
                {
                    if(check(i,j,k)) continue;
                    double d1=dis(i,j);
                    double d2=dis(i,k);
                    double d3=dis(j,k);
                    double t[3];
                    t[0]=d1,t[1]=d2,t[2]=d3;
                    sort(t,t+3);
                    if(t[0]+t[1]<=t[2]) continue;
                    b[m].x=t[0],b[m].y=t[1];
                    b[m++].z=t[2];
                }
            }
        }
        int ans=0;
        for(int i=0;i<m;i++)
        {
            int sum=1;
            for(int j=0;j<m;j++)
                if(i!=j&&gao(i,j))
                    sum++;
            if(sum>ans) ans=sum;
        }
        printf("%d\n",ans);
    }
    return 0;
}

hdu4082 Hou Yi's secret 暴力

时间: 2024-11-14 10:57:57

hdu4082 Hou Yi's secret 暴力的相关文章

[HDU 4082] Hou Yi&#39;s secret (简单计算几何)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082 题目大意: 给你n个点,问能最多构成多少个相似三角形. 用余弦定理,计算三个角度,然后暴力数有多少个,更新答案. 代码: 1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 #include <cstring> 5 #include <vector> 6 #includ

HDU 4082 Hou Yi&#39;s secret --枚举

题意: 给n个点,问最多有多少个相似三角形(三个角对应相等). 解法: O(n^3)枚举点,形成三角形,然后记录三个角,最后按三个角度依次排个序,算一下最多有多少个连续相等的三元组就可以了. 注意:在同一个坐标的两点只算一次,所以要判一下. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #includ

HDU - 4082 Hou Yi&#39;s secret

题意:射箭落在n个点,任取三点可构成一个三角形,问最大的相似三角形集(一组互相相似的三角形)的个数. 分析: 1.若n个点中有相同的点,要去重,题目中说射箭会形成洞,任选三个洞构成三角形,因此射在同一点只形成一个洞. 2.二进制枚举子集选出三个点,判断能否构成三角形. 3.因为边长可能为小数,因此用边长的平方判断相似. (1)将比较的两个三角形三边分别排序 (2)tmpx[0] / tmpy[0] = tmpx[1] / tmpy[1] = tmpx[2] / tmpy[2],即若满足tmpx[

HDU 4082 Hou Yi&#39;s secret-求相似三角形的最大个数-(坑货)

题意:找相似三角形的最大个数.注意不是所有相似三角形的个数,而是不同类相似三角形 中个数最大的 分析: 之前理解成了所有相似三角形的个数,所以尽管考虑了所有的特殊情况以及精度问题还是不停的wawawa,甚至重新写了一遍不用余弦来判断而是用边.绝望之中仔细看别人的代码,原来题意理解错了. 这题的收获: 1.三角形相似的判定:用余弦定理.或者边成比例.最好用边,然后判定的时候不用比值,用乘积,这样就不存在精度问题. 2.耐心.对自己有信心. 代码: #include<iostream> #incl

HDU 1403 Longest Common Substring(后缀数组,最长公共子串)

hdu题目 poj题目 参考了 罗穗骞的论文<后缀数组——处理字符串的有力工具> 题意:求两个序列的最长公共子串 思路:后缀数组经典题目之一(模版题) //后缀数组sa:将s的n个后缀从小到大排序后将 排序后的后缀的开头位置 顺次放入sa中,则sa[i]储存的是排第i大的后缀的开头位置.简单的记忆就是“排第几的是谁”. //名次数组rank:rank[i]保存的是suffix(i){后缀}在所有后缀中从小到大排列的名次.则 若 sa[i]=j,则 rank[j]=i.简单的记忆就是“你排第几”

编程模拟自然(七):力学矢量与牛顿定律

序 旧书有云:古者十日并出,草木焦槁,一曰后羿者射日,太阳里之九鸟皆死,救苍生于涂炭. 传闻后羿所用箭矢加持了力学模拟系统,可实现深空精确制导,才得以击落太阳. ... “星星挂在天边,就像梦想遥不可现...”元哼唧着. “猿叔你在哼什么曲子啊?” “...星星消失在天边,就像诺言来不及实现...”元对无名儿捂着双耳选择无视. “咳咳,我这是在朗诵诗人小刚的诗歌呢!” ... 第零章 “星星挂在天...你爸曾经射落过太阳?”元刚要继续深情朗诵,似乎想到了什么. “是的,听娘说爹地最厉害了.” “

URAL 1517 Freedom of Choice(后缀数组,最长公共字串)

题目 输出最长公共字串 #define maxn 200010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int cmp(int *r,int a,int b,int l) {return r[a]==r[b]&&r[a+l]==r[b+l];}//yuan lai zhi qian ba zhe li de l cuo dang cheng 1 le ... void da(int *r,int *sa,int n,int m) { int i,j

Linux下MySQL的简单使用(二)

上一篇我们介绍到一些Linux的简单命令的使用,今天我们更深入了解一下MySQL! 一.多表查询 这篇通过实例来讲述多表查询,目的是穷尽所有的场景和所有的方法,并且对每个方法的使用做实例. 首先先列举本篇用到的分类(内连接,外连接,交叉连接)和连接方法: A)内连接:join,inner join B)外连接:left join,left outer join,right join,right outer join,union C)交叉连接:cross join 首先导入hellodb.sql,

mysql之视图、存储过程、触发器、约束、授权

视图:     简单视图:单张表     复杂视图:多张,子查询     物化视图: MariaDB [hidb]> create view v1_students as select name,age from students; MariaDB [hellodb]> create view v3_students as select name,age from students where age>40 ; Query OK, 0 rows affected (0.05 sec) M