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, ...
随机推荐
- 启动storm任务时,异常提示
启动storm任务时,异常提示: 14182 [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2000] WARN o.a.s.s.o.a.z.s.NIOServerCnx ...
- 十三、web应用中路径总结
1.路径的编写形式:1)<a href="/项目名/资源路径"></a> <!--超链接--> <form action=" ...
- Python 3网络爬虫开发实战书籍
Python 3网络爬虫开发实战书籍,教你学会如何用Python 3开发爬虫 本书介绍了如何利用Python 3开发网络爬虫,书中首先介绍了环境配置和基础知识,然后讨论了urllib.reques ...
- js动态添加li,你添加的li具有你绑定的事件
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 <%@page i ...
- jenkins -- 邮件的配置
参考博文:https://blog.csdn.net/lykio_881210/article/details/81135769 https://www.jianshu.com/p/29a29ce6e ...
- P1074 宇宙无敌加法器
P1074 宇宙无敌加法器 转跳点:
- echart 库 初始
一.echart简介 Echarts (http://echarts.baidu.com/)是百度公司出品的,算是百度不可多得的良心之作.要彻底掌握Echarts,你需要掌握一点前端开发的知识,这些知 ...
- vscode点击ctrl键报错Request textDocument/definition failed.
现象 用vscode写java代码的时候突然出现,修复问题点击Ctrl时,输出窗口就打日志,报错Request textDocument/definition failed. 我百度唯一的有用线索就是 ...
- 第1节 IMPALA:2、架构介绍
impala的架构以及查询计划: impalad :从节点 对应启动一个impala-server的进程 ,主要负责各种查询计划,官方建议与所有的datanode安装在同一台机器上面 impala-s ...
- Linux-Journal
Linux-Journal 1. 日志简介 2. 日志的优先级和分类 2.1 优先级 2.2 设施分类 3. 命令帮助 4. 日志查看示例 5. 日志大小限制 6. 手动清理日志文件 1. 日志简介 ...