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 ...
随机推荐
- S2SH整合
Struts2.Spring.Hibernate三大框架在一个项目中的具体职责分配如下: 三大框架整合,导入各个框架和整合所需的包(本项目采用的是Struts2.3+spring3.0+hiberna ...
- notes/Set up development environment on windows
恰好前几天买了个新笔记本, 15存 sony vaio, 终于从mac回到了windows. 不过作为(曾经的)*nix追随者, 没有bash真是寸步难行, 幸好windows8.x有了super s ...
- php5.3.*编译出现make: *** [ext/gd/libgd/gd_compat.lo] Error 1 解决方法
升级系统,把php5.2.9升级到5.3.6,按照以前的编译参数,configure能正常通过,但是在make的时候提示: In file included from /root/php-5.3.6 ...
- static类成员(变量和函数)
0. 使用背景 对于特定类类型的全体对象而言,访问一个全局对象有时是必要的.也许,在程序的任意点需要统计已创建的特定类类型对象的数量:或者,全局对象可能是指向类的错误处理例程的一个指针:或者,它是指向 ...
- 【2013Esri全球用户大会精彩看点】ArcGIS 10.2移动产品新特性
Ø 全新的应用Explorer for ArcGIS 在2013年第四季度,Esri将发布全新的应用Explorer for ArcGIS,它将联合Collector和Operations Dashb ...
- EasyMock入门
这是一个JavaProject,有关EasyMock用法详见本文测试用例 首先是用到的实体类User.java package com.jadyer.model; public class User ...
- ehcache.xml配置参数
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoc ...
- [HMLY]10.iOS中block的基础用法
本文简介 本章不会对Block做过多的实现研究.只是讲解基本的用法.纯粹基础知识.结合实际项目怎么去做举例.Block使用场景,可以在两个界面的传值,也可以对代码封装作为参数的传递等.用过GCD就知道 ...
- js Checkbox 传递多个值给后台
------前台JS "<input class=\'jTabCheck2\' type=\'checkbox\' partvguid=" + obj + " pr ...
- 背景background
background简写:http://www.cnblogs.com/dunken/p/4380194.html
题目链接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 ...
Struts2.Spring.Hibernate三大框架在一个项目中的具体职责分配如下: 三大框架整合,导入各个框架和整合所需的包(本项目采用的是Struts2.3+spring3.0+hiberna ...
恰好前几天买了个新笔记本, 15存 sony vaio, 终于从mac回到了windows. 不过作为(曾经的)*nix追随者, 没有bash真是寸步难行, 幸好windows8.x有了super s ...
升级系统,把php5.2.9升级到5.3.6,按照以前的编译参数,configure能正常通过,但是在make的时候提示: In file included from /root/php-5.3.6 ...
0. 使用背景 对于特定类类型的全体对象而言,访问一个全局对象有时是必要的.也许,在程序的任意点需要统计已创建的特定类类型对象的数量:或者,全局对象可能是指向类的错误处理例程的一个指针:或者,它是指向 ...
Ø 全新的应用Explorer for ArcGIS 在2013年第四季度,Esri将发布全新的应用Explorer for ArcGIS,它将联合Collector和Operations Dashb ...
这是一个JavaProject,有关EasyMock用法详见本文测试用例 首先是用到的实体类User.java package com.jadyer.model; public class User ...
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoc ...
本文简介 本章不会对Block做过多的实现研究.只是讲解基本的用法.纯粹基础知识.结合实际项目怎么去做举例.Block使用场景,可以在两个界面的传值,也可以对代码封装作为参数的传递等.用过GCD就知道 ...
------前台JS "<input class=\'jTabCheck2\' type=\'checkbox\' partvguid=" + obj + " pr ...
background简写:http://www.cnblogs.com/dunken/p/4380194.html