【计算几何】FZU Problem 2270 Two Triangles
http://acm.fzu.edu.cn/problem.php?pid=2270
【题意】
给定6到10个点,从中选出6个不同的点组成两个三角形,使其中一个三角形可以通过另一个三角形平移和旋转得到。问有多少种不同的三角形选法?
【思路】
- 全等
- 排除对称
【Accepted】
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std; int n;
const double eps=1e-;
struct Point
{
int x;
int y;
Point(){}
Point(int _x,int _y):x(_x),y(_y){}
Point operator-(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
int operator^(const Point &b)const
{
return x*b.y-y*b.x;
}
int operator*(const Point &b)const
{
return x*b.x+y*b.y;
}
}p[];
bool v[][][][][][];
int dist(int i,int j)
{
return (p[i]-p[j])*(p[i]-p[j]);
}
int dis[][];
bool judge(int i,int j,int k)
{
double x=sqrt(dist(i,j));
double y=sqrt(dist(i,k));
double z=sqrt(dist(j,k));
double a[]={x,y,z};
sort(a,a+);
if(fabs(a[]+a[]-a[])<=eps)
{
return false;
}
return true;
} bool check(int i,int j,int k,int l,int m,int o,int flag)
{
int a[]={i,k,m};
int b[]={j,l,o};
sort(a,a+);
sort(b,b+);
if(v[a[]][a[]][a[]][b[]][b[]][b[]])
{
return true;
}
if(flag)
{
v[a[]][a[]][a[]][b[]][b[]][b[]]=;
}
return false;
} bool rt(int i,int j,int k,int l,int m,int o)
{
if(((p[k]-p[i])^(p[m]-p[k]))*((p[l]-p[j])^(p[o]-p[l]))<)//叉积的乘积大于等于0代表方向是一样的,如果方向不一样,说明是对称的
{
return false;
}
if(((p[m]-p[k])^(p[i]-p[m]))*((p[o]-p[l])^(p[j]-p[o]))<)
{
return false;
}
if(((p[i]-p[m])^(p[k]-p[i]))*((p[j]-p[o])^(p[l]-p[j]))<)
{
return false;
}
return true;
}
int main()
{
int T;
scanf("%d",&T);
int cas=;
while(T--)
{
//这个数组用来去重,一定要初始化
memset(v,,sizeof(v));
int ans=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(j==i) continue;
for(int k=;k<=n;k++)
{
if(k==i||k==j) continue;
for(int l=;l<=n;l++)
{
if(l==i||l==j||l==k) continue;
if(dist(i,k)!=dist(j,l)) continue;
//目前为止已经选出两个三角形对应相等的两条边ik和jl
for(int m=;m<=n;m++)
{
if(m==i||m==j||m==k||m==l) continue;
//先选出m点,排除三点共线的情况
if(!judge(i,k,m)) continue;
for(int o=;o<=n;o++)
{
if(o==i||o==j||o==k||o==l||o==m) continue;
if(dist(k,m)!=dist(l,o)||dist(m,i)!=dist(o,j)) continue;
//现在已经选出两个全等的三角形
if(check(i,j,k,l,m,o,)) continue;
//去重,如果是重复的重新选择
if(rt(i,j,k,l,m,o))//因为只能是平移和旋转得到,所以要排除对称这种情况
{
ans++;
check(i,j,k,l,m,o,);//把这种选择标记为1
}
}
}
}
}
}
}
printf("Case %d: %d\n",++cas,ans);
}
return ;
}
【计算几何】FZU Problem 2270 Two Triangles的更多相关文章
- FZu Problem 2233 ~APTX4869 (并查集 + sort)
题目链接: FZu Problem 2233 ~APTX4869 题目描述: 给一个n*n的矩阵,(i, j)表示第 i 种材料 和 第 j 种材料的影响值,这个矩阵代表这n个物品之间的影响值.当把这 ...
- FZu Problem 2236 第十四个目标 (线段树 + dp)
题目链接: FZu Problem 2236 第十四个目标 题目描述: 给出一个n个数的序列,问这个序列内严格递增序列有多少个?不要求连续 解题思路: 又遇到了用线段树来优化dp的题目,线段树节点里 ...
- 翻翻棋(找规律问题)(FZU Problem 2230)
题目是这样的: FZU Problem 2230 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃 ...
- fzu Problem 2148 Moon Game(几何 凸四多边形 叉积)
题目:http://acm.fzu.edu.cn/problem.php?pid=2148 题意:给出n个点,判断可以组成多少个凸四边形. 思路: 因为n很小,所以直接暴力,判断是否为凸四边形的方法是 ...
- fzu Problem 2140 Forever 0.5(推理构造)
题目:http://acm.fzu.edu.cn/problem.php?pid=2140 题意: 题目大意:给出n,要求找出n个点,满足: 1)任意两点间的距离不超过1: 2)每个点与(0,0)点的 ...
- Fzu Problem 2082 过路费 LCT,动态树
题目:http://acm.fzu.edu.cn/problem.php?pid=2082 Problem 2082 过路费 Accept: 528 Submit: 1654Time Limit ...
- FZU Problem 2169 shadow
http://acm.fzu.edu.cn/problem.php?pid=2169 题目大意: S王国有N个城市,有N-1条道路.王都为编号1的城市.叛军驻扎在很多城市.除了王都外有K个城市有军队, ...
- fzu Problem 2128 最长子串(KMP + strstr 经典好题)
Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长. Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...
- fzu Problem - 2232 炉石传说(二分匹配)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2232 Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石 ...
随机推荐
- Spark MLlib编程API入门系列之特征选择之向量选择(VectorSlicer)
不多说,直接上干货! 特征选择里,常见的有:VectorSlicer(向量选择) RFormula(R模型公式) ChiSqSelector(卡方特征选择). VectorSlicer用于从原来的特征 ...
- Suricata的初始化脚本
见官网 https://suricata.readthedocs.io/en/latest/initscripts.html
- pyspark中使用累加器Accumulator统计指标
评价分类模型的性能时需要用到以下四个指标 最开始使用以下代码计算,发现代码需要跑近一个小时,而且这一个小时都花在这四行代码上 # evaluate model TP = labelAndPreds.f ...
- LN : leetcode 730 Count Different Palindromic Subsequences
lc 730 Count Different Palindromic Subsequences 730 Count Different Palindromic Subsequences Given a ...
- checkbox:click事件触发文本框显示隐藏
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Delphi定时器控件TTimer“一睡不醒”问题研究
1,试验1—基础代码 1.1页面控件与代码 定时器 Timer1 Timer_work Interval 1000 1500 Enabled True True Ontimer事件 then exit ...
- [Python學習筆記] 使用xlwings 插入註解 (forked 版本)
到今天為止 xlwings 還沒有插入註解的功能 去原始開發者的 Github Pull Requests 他說之前有人有建議要加入這個功能 但他還沒更新~ 如果需要使用 Python 來插入註解的話 ...
- SQLite-Like语句
SQLite – LIKE子句 使用SQLite LIKE运算符 用于匹配文本.如果搜索表达式可以匹配模式表达式,如操作符将返回true,这是1.有两个通配符与Like操作符一起使用: The per ...
- subprocess使用小方法
import subprocess def create_process(cmd): p = subprocess.Popen(cmd, shell=True, stdout=subp ...
- HTML中pre标签的用法
我们经常会在要保持文本格式的时候使用pre标签,比如当我们要展示源代码的时候,只要放一个pre标签,然后把源代码直接复制,粘贴,然后在页面上就可以保持好格式.不会像放在其它标签里那样,把换行和空格都自 ...