HDU - 4082 Hou Yi's secret
题意:射箭落在n个点,任取三点可构成一个三角形,问最大的相似三角形集(一组互相相似的三角形)的个数。
分析:
1、若n个点中有相同的点,要去重,题目中说射箭会形成洞,任选三个洞构成三角形,因此射在同一点只形成一个洞。
2、二进制枚举子集选出三个点,判断能否构成三角形。
3、因为边长可能为小数,因此用边长的平方判断相似。
(1)将比较的两个三角形三边分别排序
(2)tmpx[0] / tmpy[0] = tmpx[1] / tmpy[1] = tmpx[2] / tmpy[2],即若满足tmpx[0] * tmpy[1] == tmpy[0] * tmpx[1] && tmpx[1] * tmpy[2] == tmpx[2] * tmpy[1],则两三角形相似。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const LL MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 1000000 + 10;
using namespace std;
struct Node{
int x, y;
}num[20];
struct tri{
LL a, b, c;
}num1[MAXN];
int cnt;
int cntpoint;
vector<int> v;
LL tmpx[5];
LL tmpy[5];
map<pair<int, int>, int> mp;
bool judge(LL x, LL y){
tmpx[0] = num1[x].a;
tmpx[1] = num1[x].b;
tmpx[2] = num1[x].c;
tmpy[0] = num1[y].a;
tmpy[1] = num1[y].b;
tmpy[2] = num1[y].c;
sort(tmpx, tmpx + 3);
sort(tmpy, tmpy + 3);
if(tmpx[0] * tmpy[1] == tmpy[0] * tmpx[1] && tmpx[1] * tmpy[2] == tmpx[2] * tmpy[1]) return true;
return false;
}
int main(){
int n;
while(scanf("%d", &n) == 1){
if(!n) return 0;
mp.clear();
cntpoint = 0;
int x, y;
for(int i = 0; i < n; ++i){
scanf("%d%d", &x, &y);
if(!mp.count(pair<int, int>(x, y))){
mp[pair<int, int>(x, y)] = 1;
num[cntpoint].x = x;
num[cntpoint++].y = y;
}
}
cnt = 0;
for(int i = 0; i < (1 << cntpoint); ++i){
v.clear();
for(int j = 0; j < cntpoint; ++j){
if(i & (1 << j)){
v.push_back(j);
}
}
if(v.size() == 3){
int tmp11 = (num[v[0]].x - num[v[1]].x) * (num[v[0]].x - num[v[1]].x) +(num[v[0]].y - num[v[1]].y) * (num[v[0]].y - num[v[1]].y);
int tmp22 = (num[v[1]].x - num[v[2]].x) * (num[v[1]].x - num[v[2]].x) +(num[v[1]].y - num[v[2]].y) * (num[v[1]].y - num[v[2]].y);
int tmp33 = (num[v[2]].x - num[v[0]].x) * (num[v[2]].x - num[v[0]].x) +(num[v[2]].y - num[v[0]].y) * (num[v[2]].y - num[v[0]].y);
double tmp1 = sqrt(double(tmp11));
double tmp2 = sqrt(double(tmp22));
double tmp3 = sqrt(double(tmp33));
if(dcmp(tmp1 + tmp2, tmp3) > 0 && dcmp(tmp2 + tmp3, tmp1) > 0 && dcmp(tmp1 + tmp3, tmp2) > 0){
num1[cnt].a = (LL)tmp11;
num1[cnt].b = (LL)tmp22;
num1[cnt].c = (LL)tmp33;
++cnt;
}
}
}
int ans = 0;
for(int i = 0; i < cnt; ++i){
int sum = 1;
for(int j = 0; j < cnt; ++j){
if(i != j){
if(judge(i, j)) ++sum;
}
}
ans = max(ans, sum);
}
printf("%d\n", ans);
}
return 0;
}
HDU - 4082 Hou Yi's secret的更多相关文章
- hdu 4082 Hou Yi's secret(暴力枚举)
Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- [HDU 4082] Hou Yi's secret (简单计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082 题目大意: 给你n个点,问能最多构成多少个相似三角形. 用余弦定理,计算三个角度,然后暴力数有多 ...
- HDU 4082 Hou Yi's secret --枚举
题意: 给n个点,问最多有多少个相似三角形(三个角对应相等). 解法: O(n^3)枚举点,形成三角形,然后记录三个角,最后按三个角度依次排个序,算一下最多有多少个连续相等的三元组就可以了. 注意:在 ...
- HDU 4082 Hou Yi's secret(暴力)
直接6重循环就行了吧...判三角形相似直接从小到大枚举两向量夹角是否相等就行了.注意去重点跟三点共线就行了... #include<algorithm> #include<iostr ...
- HDU 1403 Longest Common Substring(后缀数组,最长公共子串)
hdu题目 poj题目 参考了 罗穗骞的论文<后缀数组——处理字符串的有力工具> 题意:求两个序列的最长公共子串 思路:后缀数组经典题目之一(模版题) //后缀数组sa:将s的n个后缀从小 ...
- HDU 3518 Boring counting(后缀数组,字符处理)
题目 参考自:http://blog.sina.com.cn/s/blog_64675f540100k9el.html 题目描述: 找出一个字符串中至少重复出现两次的字串的个数(重复出现时不能重叠). ...
- Play on Words HDU - 1116 (并查集 + 欧拉通路)
Play on Words HDU - 1116 Some of the secret doors contain a very interesting word puzzle. The team o ...
- sql游标的使用
转载:http://www.cnblogs.com/moss_tan_jun/archive/2011/11/26/2263988.html 游标是邪恶的! 在关系数据库中,我们对于查询的思考是面向集 ...
- 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, ...
随机推荐
- 十三、web应用中路径总结
1.路径的编写形式:1)<a href="/项目名/资源路径"></a> <!--超链接--> <form action=" ...
- Metasploit学习笔记——移动环境渗透测试
书364页配置假冒AP步骤,因为没有无线网卡,先跳过这个实验.
- 深入理解python(二)python基础知识之数据结构
数据结构 Python中的内置数据结构(Built-in Data Structure):列表list.元组tuple.字典dict.集合set,这里只着重说前三个 >>> d=di ...
- 074、Java面向对象之构造方法重载
01.代码如下: package TIANPAN; class Book { // 定义一个新的类 private String title; // 书的名字 private double price ...
- MAC电脑如何播放.SWF文件
很简单,不需要专门的播放器,只需要将.swf文件直接拖拽到浏览器页面就可以播放了. 亲测safari , 谷歌chrome浏览器,火狐浏览器 ,都是可以的 下面是图示 step1 电脑上找到swf文件 ...
- Github版本控制系统
Git是什么? Git是目前世界上最先进的分布式版本控制系统(没有之一). 特别推荐简单易懂的廖雪锋大神制作的学习教程: https://www.liaoxuefeng.com/wiki/896043 ...
- 【LOJ2513】「BJOI2018」治疗之雨
题意 你现在有 \(m+1\) 个数:第一个为 \(p\) ,最小值为 \(0\) ,最大值为 \(n\) :剩下 \(m\) 个都是无穷,没有最小值或最大值.你可以进行任意多轮操作,每轮操作如下: ...
- python2学习------基础语法2(函数)
1.函数 # 无参数函数 def loopTest2(): a=1; while a<40: print a; a=a+1; if a==35: continue; else: print 'o ...
- arm linux 移植 rsync
背景: 在产品开发中可以使用rsync进行大文件的拷贝,断点续传. host平台 :Ubuntu 16.04 arm平台 : 3531d rsync :3.1.3 arm-gcc :4.9.4 ...
- 2013蓝桥杯预赛C/C++本科B组
题目标题: 高斯日记 大数学家高斯有个好习惯:无论如何都要记日记. 他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210 后来人们知道,那个整数就是日期,它表示那一天是高斯 ...