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, ...
随机推荐
- English-Phonics
English-Phonics 1. 音节 1.1 字组 1.2 音节概述及分类 1.3 音节的划分 2. 元音字组的自然发音 2.1 元音字母 2.2 元音字母的长音 2.3 元音字母+r 2.4 ...
- 【深入】 - AST抽象语法树
参考: https://segmentfault.com/a/1190000016231512
- lambda表达式和for_each,find_if
1 lambda表达式可以允许我传递任意可调用对象,必须要有捕获列表和函数体,标准形式是[捕获列表] (参数列表)->return tpye{函数体} 谓词:一元谓词指的是只能接受一个传入参数, ...
- 077、Java数组之分步实现数组操作
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- C# 篇基础知识7——字符串
文字是信息的主要表达方式,因此文字处理是计算机的一项重要功能之一.现在来深入研究C#中字符串的各种特性.正则表达式的基本概念以及如何用正则表达式进行文本匹配. 1.char结构 C#中的字符用Syst ...
- Anaconda下的 Jupyter Notebook 安装 多python环境
装完 Anaconda 会自带一个pyhon环境 也会自带Jupyter Notebook 可以点击开始中的Jupyter Notebook 打开 浏览器 我这里是 3.x 想要装个2.7 的 ...
- HTML<a>标签作为锚链接
1. 什么是锚链接? <a></a>标签主要作为超链接和锚链接使用.超链接主要指不同html页面之间的跳转,而锚链接指的是同一页面之间的跳转. 锚链接的两种效果: 在当前页面中 ...
- 《ES6标准入门》(阮一峰)--12.Symbol
1.概述 ES5 的对象属性名都是字符串,这容易造成属性名的冲突.比如,你使用了一个他人提供的对象,但又想为这个对象添加新的方法(mixin 模式),新方法的名字就有可能与现有方法产生冲突.如果有一种 ...
- MySQL学习之SQL基础(一)DDL
Sql基础 DDL (data defination language) 创建表 CREATE TABLE emp( ename varchar(10), hiredate date, sal dec ...
- mybatis连接数据库出错获取不到SQLsession
采用mybatis连接数据库时候出现的问题描述: 数据库连接配置正确,mybatis-config数据库等部分配置均正确,连接数据库是OK的 <properties resource=" ...