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 ...
随机推荐
- appfog java jdbc mysql连接
本来用得好好的openshift被墙了,无奈只能找过一个免费的空间.同学推荐appfog,appfog的确是一个很好用的空间,支持几乎所有主流的技术.我自己喜欢写点java,刚好我就开始使用了.app ...
- Java静态代理和动态代理
今天介绍一下代理设计模式,在业务场景中使用代理模式的好处有很多,包括什么权限校验,事务管理等等,具体有什么好处大家自动百度吧,我这里只解释代理模式的设计原理.首先这个设计模式出来的时候先是静态代理模式 ...
- Python -- machine learning, neural network -- PyBrain 机器学习 神经网络
I am using pybrain on my Linuxmint 13 x86_64 PC. As what it is described: PyBrain is a modular Machi ...
- 32位Win7下安装与配置PHP环境(二)
本安装实例中用到的三个软件,都可以直接从官网下载,为了方便,也可以直接从本人的CSDN资源中打包下载. 三个安装文件如图示: CSDN高速下载地址: http://download.csdn.net/ ...
- 使用SmsManager服务群发短信
SmsManager是Android提供的一个非常常见的服务,SmsManager提供了一系列sendXxxMessage()方法用于发送短信,不过短信通常都是普通文本,调用sendTextMessa ...
- 你不知道的Eclipse用法:使用Allocation tracker跟踪Android应用内存分配
Android Tools中的DDMS带有一个很不错的跟踪内存分配的工具Allocation tracker.通过Alloction tracker,不仅知道分配了哪类对象,还可以知道在哪个线程.哪个 ...
- 用ajax对数据进行查看人员信息
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 生成UUID简易版
最近一体化项目的主键ID都要求使用UUID,生成方法如下: import org.safehaus.uuid.UUIDGenerator; /** UUID生成器对象 */ private ...
- Android 动态监听网络 断网重连
需求: 网络连接断开 弹出popupwindow 当前网络连接断开 网络恢复时popupwindow 消失重新请求网络. 需求描述完毕 上一张帅图 思路:广播 发送及时消息 断网flag popup ...
- Prefix the choice with ! to persist it to bower.json ? Answer (问你选择哪个1,2,3.........)
Unable to find a suitable version for underscore, please choose one by typing on e of the numbers be ...
题目链接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 ...
本来用得好好的openshift被墙了,无奈只能找过一个免费的空间.同学推荐appfog,appfog的确是一个很好用的空间,支持几乎所有主流的技术.我自己喜欢写点java,刚好我就开始使用了.app ...
今天介绍一下代理设计模式,在业务场景中使用代理模式的好处有很多,包括什么权限校验,事务管理等等,具体有什么好处大家自动百度吧,我这里只解释代理模式的设计原理.首先这个设计模式出来的时候先是静态代理模式 ...
I am using pybrain on my Linuxmint 13 x86_64 PC. As what it is described: PyBrain is a modular Machi ...
本安装实例中用到的三个软件,都可以直接从官网下载,为了方便,也可以直接从本人的CSDN资源中打包下载. 三个安装文件如图示: CSDN高速下载地址: http://download.csdn.net/ ...
SmsManager是Android提供的一个非常常见的服务,SmsManager提供了一系列sendXxxMessage()方法用于发送短信,不过短信通常都是普通文本,调用sendTextMessa ...
Android Tools中的DDMS带有一个很不错的跟踪内存分配的工具Allocation tracker.通过Alloction tracker,不仅知道分配了哪类对象,还可以知道在哪个线程.哪个 ...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
最近一体化项目的主键ID都要求使用UUID,生成方法如下: import org.safehaus.uuid.UUIDGenerator; /** UUID生成器对象 */ private ...
需求: 网络连接断开 弹出popupwindow 当前网络连接断开 网络恢复时popupwindow 消失重新请求网络. 需求描述完毕 上一张帅图 思路:广播 发送及时消息 断网flag popup ...
Unable to find a suitable version for underscore, please choose one by typing on e of the numbers be ...