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, ...
随机推荐
- 命令打开java控制面板
运行一些java程序时,会提示java安全阻止,需要手动运行,java7一起更改安全级别为“中”就可以了,java8需要配置信任网站 . 这些操作都需要在java控制面板进行,经常会出现无法在控制面板 ...
- LoadRunner监控Linux系统
需要下载3个包: 地址链接:链接:https://pan.baidu.com/s/1lltAa6JnjJ7Mr88duixUSQ 密码:5yiw(1)rsh-0.17-14.i386.rpm (2) ...
- fiddler抓取URL之过滤设置
Fiddler是强大的抓包工具,它的原理是以web代理服务器的形式进行工作的,使用的代理地址是:127.0.0.1,端口默认为8888,我们也可以通过设置进行修改. 只要是开启了fiddler,我们的 ...
- Spring声明式事物原理分析
基础准备 pom <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...
- 2-10 就业课(2.0)-oozie:2、介绍和安装1
oozie的安装及使用 1. oozie的介绍 Oozie是运行在hadoop平台上的一种工作流调度引擎,它可以用来调度与管理hadoop任务,如,MapReduce.Pig等.那么,对于Oozie ...
- Aop配置时候的一些问题
编写切面,并在ApplicationContest.xml 中相关AOP及切面的配置完全正确的情况下,运行报错如下: Exception in thread "main" org. ...
- nodejs配置 https服务
const port = normalizePort(process.env.PORT || '3000'); const path = require('path'); const https = ...
- Java的SPI机制
目录 1. 什么是SPI 2. 为什么要使用SPI 3. 关于策略模式和SPI的几点区别 4. 使用介绍或者说约定 4.1 首先介绍几个名词 4.2 约定 5. 具体的demo实现 5.1 创建服务提 ...
- GoJS实例2
复制如下内容保存到空白的.html文件中,用浏览器打开即可查看效果 <!DOCTYPE html> <html> <head> <meta name=&quo ...
- 关于AlertDialog多选框中全选和反选的实现办法
package mobile.android.ch07.multi.choice.dialog; import android.app.Activity; import android.app.Ale ...