HDU 5839 Special Tetrahedron
HDU 5839 Special Tetrahedron
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839
Description
Given n points which are in three-dimensional space(without repetition).
Please find out how many distinct Special Tetrahedron among them. A tetrahedron is called Special Tetrahedron if it has two following characters.
- At least four edges have the same length.
- If it has exactly four edges of the same length, the other two edges are not adjacent.
Input
t 组数据,n(n <= 200)个点,每个点的三维坐标。
Output
求出多少个四面体满足条件。
Sample Input
2
4
0 0 0
0 1 1
1 0 1
1 1 0
9
0 0 0
0 0 2
1 1 1
-1 -1 1
1 -1 1
-1 1 1
1 1 0
1 0 1
0 1 1
Sample Output
Case #1: 1
Case #2: 6
题意:
给你最多200个点让你找出其中不同的四面体,要求这个四面体至少四条边相同,如果只有四条边相同,剩下的两条边不共顶点。
题解:
做题的时候想到了这么做但是一分析n^4的复杂度就放弃了,结果结束后看别人的题解发现这个复杂度加上剪枝可过,怼了一发。
首先是枚举三个点,如果三点不组成一个平面,或者三点组成的三角形三边都不相同,那么继续枚举下一组三点。如果枚举的三点满足条件,再枚举剩下的可以作为第四个的点,判断是否满足条件。这样的四点组数就出来了。
因为至少四条边相同。现在我们先以任一点为顶点,如果它到其他三点距离相同,那么如果剩下的三个点是等腰三角形则符合条件。如果到其他三点距离有两个相同,那么我枚举三组相同的边,则不同的边以及对边就出来了,可以容易判断。至于定点到底面三边不相同直接不符合条件。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct Point {
LL x,y,z;
Point operator - (Point &R)const{
Point ret;
ret.x = x - R.x;
ret.y = y - R.y;
ret.z = z - R.z;
return ret;
}
}p[300];
int n;
inline LL line2(Point &a,Point &b)
{
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z);
}
inline LL gx(Point &a,Point &b,Point &c)
{
Point l1,l2;
l1 = a-b;
l2 = a-c;
if ((l1.x*l2.y == l1.y*l2.x) && (l1.x*l2.z == l1.z*l2.x) && (l1.y*l2.z == l1.z*l2.y)) return true;
return false;
}
inline LL fourm(Point &d,Point &a,Point &b,Point &c)
{
LL s[4][4];
s[1][1] = d.x-a.x;s[1][2] = d.y-a.y;s[1][3] = d.z-a.z;
s[2][1] = d.x-b.x;s[2][2] = d.y-b.y;s[2][3] = d.z-b.z;
s[3][1] = d.x-c.x;s[3][2] = d.y-c.y;s[3][3] = d.z-c.z;
LL ans1,ans2;
ans1 = s[1][1]*s[2][2]*s[3][3] + s[1][2]*s[2][3]*s[3][1] + s[1][3]*s[2][1]*s[3][2];
ans2 = s[1][3]*s[2][2]*s[3][1] + s[1][1]*s[2][3]*s[3][2] + s[1][2]*s[2][1]*s[3][3];
if (ans1 == ans2) return false;
return true;
}
inline bool fin(Point &d,Point &a,Point &b,Point &c)
{
LL l1,l2,l3,l4,l5,l6;
l1 = line2(a,b);
l2 = line2(b,c);
l3 = line2(a,c);
l4 = line2(a,d);
l5 = line2(b,d);
l6 = line2(d,c);
if (l4 == l5 && l5 == l6){
if ( ((l1 == l3) && (l1 == l4)) || ((l1 == l2) && (l1 == l4)) || ((l2 == l3)&&(l2 == l4)) ) return true;
}else if (l4 == l5){
if (l2 == l3 && l2 == l4) return true;
}else if (l5 == l6){
if (l1 == l3 && l1 == l5) return true;
}else if (l4 == l6){
if (l1 == l2 && l1 == l4) return true;
}
return false;
}
inline int solve()
{
int ans = 0;
LL ll1,ll2,ll3;
for (int d1 = 1; d1 <= n; d1++){
for (int d2 = d1+1; d2 <= n; d2++){
ll3 = line2(p[d1],p[d2]);
for (int d3 = d2+1; d3 <= n; d3++){
ll1 = line2(p[d2],p[d3]);
ll2 = line2(p[d1],p[d3]);
if (ll1 != ll2 && ll1 != ll3 && ll2 != ll3)
continue;
if (gx(p[d1],p[d2],p[d3]))
continue;
for (int d4 = d3+1; d4 <= n; d4++){
if (fourm(p[d4],p[d1],p[d2],p[d3])){
bool te = false;
if (fin(p[d4],p[d1],p[d2],p[d3])){
ans++;
}
}
}
}
}
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
for (int _t = 1; _t <= t; _t++){
scanf("%d",&n);
for (int i = 1; i <= n; i++) scanf("%lld %lld %lld",&p[i].x,&p[i].y,&p[i].z);
printf("Case #%d: %d\n",_t,solve());
}
return 0;
}
HDU 5839 Special Tetrahedron的更多相关文章
- HDU 5839 Special Tetrahedron (计算几何)
Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
- HDU 5839 Special Tetrahedron 计算几何
Special Tetrahedron 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
- HDU 5839 Special Tetrahedron (2016CCPC网络赛08) (暴力+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不 ...
- (四面体)CCPC网络赛 HDU5839 Special Tetrahedron
CCPC网络赛 HDU5839 Special Tetrahedron 题意:n个点,选四个出来组成四面体,要符合四面体至少四条边相等,若四条边相等则剩下两条边不相邻,求个数 思路:枚举四面体上一条线 ...
- hdu 5839(三维几何)
Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 【HDU 5839】Special Tetrahedron(计算几何)
空间的200个点,求出至少四边相等,且其余两边必须不相邻的四面体的个数. 用map记录距离点i为d的点有几个,这样来优化暴力的四重循环. 别人的做法是枚举两点的中垂面上的点,再把到中点距离相等的点找出 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 3395 Special Fish(拆点+最大费用最大流)
Special Fish Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU 4569 Special equations (数学题)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4569 题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0. 题解:f(x)%(p ...
随机推荐
- [置顶] JAVA从零单排4-----继承、封装和多态详解
继承 Java三大特征之一:继承.Java的继承具有单继承的特点,每个子类只能有一个直接父类. 继承的特点 Java的继承用extends关键字来实现,被继承的类成为父类,实现继承的类被称为子类.子类 ...
- Cloudera Development Kit(CDK) 简介
Cloudera Development Kit(CDK) 简介 guibin.beijing@gmail.com 2013.07.02 CDK简介 CDK(Cloudera Development ...
- Dreamer 框架 比Struts2 更加灵活
winter 改名为Dreamer. 这次发布第二个版本. 这次修复了很多BUG 和完善了部分功能. 1.改进用户服务层 以后在服务层中只需要继承BaseSupport 泛型类 就可以实现对对象进行增 ...
- 【CSS】定位元素居中显示
1.利用margin div { width: 100px; height: 100px; background-color: skyblue; position: absolute; top: 50 ...
- Android基础知识-1
1.Android的Activity任务栈 在Android的系统中,在APP运行时每个APP都会默认有一个任务栈,任务栈的名称以APP的包名命名.任务栈是一中先进后出的结构,APP中每一个调用的Ac ...
- PHP连接MSSQL数据库案例,PHPWAMP多个PHP版本连接SQL Server数据库
课前小知识普及:MSSQL和SQL Server是同一个软件,叫法不同而已,MSSQL全称是Microsoft SQL Server,MSSQL是简写,有些人则喜欢直接叫SQL Server,我就比较 ...
- JSON对象和字符串的转换
JSON.parse()和JSON.stringify() 1.parse 用于从一个字符串中解析出json 对象.例如 var str='{"name":"cpf& ...
- # 关于string
关于string 头文件 #include <string> using std::string; string定义和初始化 string s1; string s2(s1); strin ...
- python爆破zip脚本
最近在提高自己编程能力,拿一些实用的小工具练下.该脚本为python语言,主要涉及模块zipfile,threadings模块. 功能:暴力猜解zip解压密码 #coding: utf-8 impor ...
- SSH通过超链接传递中文参数出现乱码问题
通过超链接传递中文参数出现乱码问题 tomcat中的server.xml文件中修改如下配置: <Connector port="8080" protocol="HT ...
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839
Description
Given n points which are in three-dimensional space(without repetition).
Please find out how many distinct Special Tetrahedron among them. A tetrahedron is called Special Tetrahedron if it has two following characters.
- At least four edges have the same length.
- If it has exactly four edges of the same length, the other two edges are not adjacent.
Input
t 组数据,n(n <= 200)个点,每个点的三维坐标。
Output
求出多少个四面体满足条件。
Sample Input
2
4
0 0 0
0 1 1
1 0 1
1 1 0
9
0 0 0
0 0 2
1 1 1
-1 -1 1
1 -1 1
-1 1 1
1 1 0
1 0 1
0 1 1
Sample Output
Case #1: 1
Case #2: 6
题意:
给你最多200个点让你找出其中不同的四面体,要求这个四面体至少四条边相同,如果只有四条边相同,剩下的两条边不共顶点。
题解:
做题的时候想到了这么做但是一分析n^4的复杂度就放弃了,结果结束后看别人的题解发现这个复杂度加上剪枝可过,怼了一发。
首先是枚举三个点,如果三点不组成一个平面,或者三点组成的三角形三边都不相同,那么继续枚举下一组三点。如果枚举的三点满足条件,再枚举剩下的可以作为第四个的点,判断是否满足条件。这样的四点组数就出来了。
因为至少四条边相同。现在我们先以任一点为顶点,如果它到其他三点距离相同,那么如果剩下的三个点是等腰三角形则符合条件。如果到其他三点距离有两个相同,那么我枚举三组相同的边,则不同的边以及对边就出来了,可以容易判断。至于定点到底面三边不相同直接不符合条件。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct Point {
LL x,y,z;
Point operator - (Point &R)const{
Point ret;
ret.x = x - R.x;
ret.y = y - R.y;
ret.z = z - R.z;
return ret;
}
}p[300];
int n;
inline LL line2(Point &a,Point &b)
{
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z);
}
inline LL gx(Point &a,Point &b,Point &c)
{
Point l1,l2;
l1 = a-b;
l2 = a-c;
if ((l1.x*l2.y == l1.y*l2.x) && (l1.x*l2.z == l1.z*l2.x) && (l1.y*l2.z == l1.z*l2.y)) return true;
return false;
}
inline LL fourm(Point &d,Point &a,Point &b,Point &c)
{
LL s[4][4];
s[1][1] = d.x-a.x;s[1][2] = d.y-a.y;s[1][3] = d.z-a.z;
s[2][1] = d.x-b.x;s[2][2] = d.y-b.y;s[2][3] = d.z-b.z;
s[3][1] = d.x-c.x;s[3][2] = d.y-c.y;s[3][3] = d.z-c.z;
LL ans1,ans2;
ans1 = s[1][1]*s[2][2]*s[3][3] + s[1][2]*s[2][3]*s[3][1] + s[1][3]*s[2][1]*s[3][2];
ans2 = s[1][3]*s[2][2]*s[3][1] + s[1][1]*s[2][3]*s[3][2] + s[1][2]*s[2][1]*s[3][3];
if (ans1 == ans2) return false;
return true;
}
inline bool fin(Point &d,Point &a,Point &b,Point &c)
{
LL l1,l2,l3,l4,l5,l6;
l1 = line2(a,b);
l2 = line2(b,c);
l3 = line2(a,c);
l4 = line2(a,d);
l5 = line2(b,d);
l6 = line2(d,c);
if (l4 == l5 && l5 == l6){
if ( ((l1 == l3) && (l1 == l4)) || ((l1 == l2) && (l1 == l4)) || ((l2 == l3)&&(l2 == l4)) ) return true;
}else if (l4 == l5){
if (l2 == l3 && l2 == l4) return true;
}else if (l5 == l6){
if (l1 == l3 && l1 == l5) return true;
}else if (l4 == l6){
if (l1 == l2 && l1 == l4) return true;
}
return false;
}
inline int solve()
{
int ans = 0;
LL ll1,ll2,ll3;
for (int d1 = 1; d1 <= n; d1++){
for (int d2 = d1+1; d2 <= n; d2++){
ll3 = line2(p[d1],p[d2]);
for (int d3 = d2+1; d3 <= n; d3++){
ll1 = line2(p[d2],p[d3]);
ll2 = line2(p[d1],p[d3]);
if (ll1 != ll2 && ll1 != ll3 && ll2 != ll3)
continue;
if (gx(p[d1],p[d2],p[d3]))
continue;
for (int d4 = d3+1; d4 <= n; d4++){
if (fourm(p[d4],p[d1],p[d2],p[d3])){
bool te = false;
if (fin(p[d4],p[d1],p[d2],p[d3])){
ans++;
}
}
}
}
}
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
for (int _t = 1; _t <= t; _t++){
scanf("%d",&n);
for (int i = 1; i <= n; i++) scanf("%lld %lld %lld",&p[i].x,&p[i].y,&p[i].z);
printf("Case #%d: %d\n",_t,solve());
}
return 0;
}
Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
Special Tetrahedron 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不 ...
CCPC网络赛 HDU5839 Special Tetrahedron 题意:n个点,选四个出来组成四面体,要符合四面体至少四条边相等,若四条边相等则剩下两条边不相邻,求个数 思路:枚举四面体上一条线 ...
Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
空间的200个点,求出至少四边相等,且其余两边必须不相邻的四面体的个数. 用map记录距离点i为d的点有几个,这样来优化暴力的四重循环. 别人的做法是枚举两点的中垂面上的点,再把到中点距离相等的点找出 ...
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
Special Fish Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4569 题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0. 题解:f(x)%(p ...
继承 Java三大特征之一:继承.Java的继承具有单继承的特点,每个子类只能有一个直接父类. 继承的特点 Java的继承用extends关键字来实现,被继承的类成为父类,实现继承的类被称为子类.子类 ...
Cloudera Development Kit(CDK) 简介 guibin.beijing@gmail.com 2013.07.02 CDK简介 CDK(Cloudera Development ...
winter 改名为Dreamer. 这次发布第二个版本. 这次修复了很多BUG 和完善了部分功能. 1.改进用户服务层 以后在服务层中只需要继承BaseSupport 泛型类 就可以实现对对象进行增 ...
1.利用margin div { width: 100px; height: 100px; background-color: skyblue; position: absolute; top: 50 ...
1.Android的Activity任务栈 在Android的系统中,在APP运行时每个APP都会默认有一个任务栈,任务栈的名称以APP的包名命名.任务栈是一中先进后出的结构,APP中每一个调用的Ac ...
课前小知识普及:MSSQL和SQL Server是同一个软件,叫法不同而已,MSSQL全称是Microsoft SQL Server,MSSQL是简写,有些人则喜欢直接叫SQL Server,我就比较 ...
JSON.parse()和JSON.stringify() 1.parse 用于从一个字符串中解析出json 对象.例如 var str='{"name":"cpf& ...
关于string 头文件 #include <string> using std::string; string定义和初始化 string s1; string s2(s1); strin ...
最近在提高自己编程能力,拿一些实用的小工具练下.该脚本为python语言,主要涉及模块zipfile,threadings模块. 功能:暴力猜解zip解压密码 #coding: utf-8 impor ...
通过超链接传递中文参数出现乱码问题 tomcat中的server.xml文件中修改如下配置: <Connector port="8080" protocol="HT ...