题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082

题目大意:

给你n个点,问能最多构成多少个相似三角形。

用余弦定理,计算三个角度,然后暴力数有多少个,更新答案。

代码:

 #include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
typedef pair<int,int> PII;
typedef long long LL; #define EPS 1e-8
#define PB push_back struct POINT{
int x,y;
double dis(const POINT& b){
return sqrt( double(x-b.x)*double(x-b.x)+double(y-b.y)*double(y-b.y) );
}
POINT(int ax=,int ay=):x(ax),y(ay){}
bool operator==(const POINT &b) const{
return x==b.x&&y==b.y;
}
bool operator<(const POINT &b) const{
if( x==b.x ) return y<b.y;
return x<b.x;
}
}; struct triangle{
double cosa[];
triangle(){} triangle(POINT a,POINT b,POINT c){
double A = a.dis(b);
double B = a.dis(c);
double C = b.dis(c); cosa[] = (A*A+B*B-C*C)/(*A*B);
cosa[] = (B*B+C*C-A*A)/(*B*C);
cosa[] = (A*A+C*C-B*B)/(*A*C);
sort(cosa,cosa+);
} triangle(double a,double b,double c){
cosa[] = a;
cosa[] = b;
cosa[] = c;
sort(cosa,cosa+);
} bool operator==(const triangle& b) const{
return fabs(cosa[]-b.cosa[])<EPS&&fabs(cosa[]-b.cosa[])<EPS&&fabs(cosa[]-b.cosa[])<EPS;
} }; bool isLine(POINT a,POINT b,POINT c){
return (c.x-a.x)*(b.y-a.y) == (b.x-a.x)*(c.y-a.y);
} POINT pt[];
int n; int main(){
while( scanf("%d",&n)!=EOF && n ){
set<POINT> st;
int ptrb = ;
for(int i=;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
if( st.find(POINT(x,y))==st.end() ){
pt[ptrb++] = POINT(x,y);
st.insert(POINT(x,y));
}
} vector<triangle> vec;
for(int i=;i<ptrb;i++){
for(int j=i+;j<ptrb;j++){
for(int k=j+;k<ptrb;k++){
if( !isLine(pt[i],pt[j],pt[k])){
vec.PB(triangle(pt[i],pt[j],pt[k]));
}
}
}
} int maxn = ; for(size_t i=;i<vec.size();i++){
int as = ; for(size_t j=i+;j<vec.size();j++){
if( vec[i]==vec[j] ) as++;
}
maxn = max(as,maxn);
}
printf("%d\n",maxn);
}
return ;
}

[HDU 4082] Hou Yi's secret (简单计算几何)的更多相关文章

  1. hdu 4082 Hou Yi's secret(暴力枚举)

    Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 4082 Hou Yi's secret --枚举

    题意: 给n个点,问最多有多少个相似三角形(三个角对应相等). 解法: O(n^3)枚举点,形成三角形,然后记录三个角,最后按三个角度依次排个序,算一下最多有多少个连续相等的三元组就可以了. 注意:在 ...

  3. HDU 4082 Hou Yi's secret(暴力)

    直接6重循环就行了吧...判三角形相似直接从小到大枚举两向量夹角是否相等就行了.注意去重点跟三点共线就行了... #include<algorithm> #include<iostr ...

  4. HDU - 4082 Hou Yi's secret

    题意:射箭落在n个点,任取三点可构成一个三角形,问最大的相似三角形集(一组互相相似的三角形)的个数. 分析: 1.若n个点中有相同的点,要去重,题目中说射箭会形成洞,任选三个洞构成三角形,因此射在同一 ...

  5. 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)

    Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...

  6. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  7. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  8. ●POJ 1556 The Doors(简单计算几何+最短路)

    ●赘述题目 10*10的房间内,有竖着的一些墙(不超过18个).问从点(0,5)到(10,5)的最短路. 按照输入样例,输入的连续5个数,x,y1,y2,y3,y4,表示(x,0--y1),(x,y2 ...

  9. HDU 4720 Naive and Silly Muggles (简单计算几何)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

随机推荐

  1. Apache Kafka 分布式消息队列中间件安装与配置 转载

    bin/zkServer.sh start /home/guym/down/kafka_2.8.0-0.8.0/config/zookeeper.properties& bin/kafka-s ...

  2. form表单元素类型

    <form> <input type="text"> <input type="password"> <input t ...

  3. redis报错Windows error 0x70(a large memory)

    redis报错Windows error 0x70 redis 嫌弃你内存不够了,就给你不开第二个实例. The Windows version of Redis allocates a large ...

  4. get跟post编码--转

    1.Get是用来从服务器上获得数据(没有请求体),而Post是用来向服务器上传递数据(包含请求体). 2.Get将表单中数据的按照variable=value的形式,添加到action(服务)所指向的 ...

  5. smarty变量调节器案例

    要求: 如下图,有内容的每一行,当鼠标放上去显示灰色区域,当鼠标离开灰色区域消失

  6. Angular学习(4)- 数组双向梆定

    示例: <!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 4< ...

  7. 关于checkbox的attr无效的问题

    jq用了10版本的,一直发现attr无效,查找良久,由同事帮忙解决该问题,感谢. 特记录下该问题. 由于 新版本attr换成了prop的问题. $("input[name='delIds'] ...

  8. vmware在非正常关机后无法启动虚拟机

    昨天使用vmware,由于笔记本温度过高,系统自动断电,导致实体机非正常关机.然后发现vmware无法启动虚拟机了,提示为‘This virtual machine appears to be in ...

  9. 【hibernate】之标注枚举类型@Enumerated(转载)

    实体Entity中通过@Enumerated标注枚举类型,例如将CustomerEO实体中增加一个CustomerType类型的枚举型属性,标注实体后的代码如下所示. @Entity @Table(n ...

  10. 黄聪:wordpress在IIS8中设置默认编码(windows2012服务器)

    web.config中配置 <?xml version="1.0" encoding="UTF-8"?> <configuration> ...