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 ...
随机推荐
- CI持续集成
CI持续集成 “我的TDD实践”系列之CI持续集成 写在前面: 我的TDD实践这几篇文章主要是围绕测试驱动开发所展开的,其中涵盖了一小部分测试理论,更多的则是关注工具的使用及环境的搭建,做到简单实践先 ...
- Go - Revel框架介绍
Go - Revel框架介绍 https://github.com/robfig/revel http://robfig.github.io/revel/ web框架:revel 数据库:mongod ...
- asp.net做的网站账号登陆后注销不管用了
最近做了个项目用到了数据库登录,A登陆后把登录状态保,个人信息存在Session里,但是奇怪的是,只要有一个用户登录后在其他电脑上打开上述页面,则也显示A登录状态,注销也不管用了.以前还号的.求大神啊 ...
- php memcached+Mysql(主从)
/* index.php 程序入口,用来构造sql(如查询,更新) config.php 配置参数(memcache,mysql) init.php 封装memcached操作(memca ...
- 用indexOf获取字符窜某个字符的所有位置
indexOf方法可以传两个参数,第二个参数是传位置的参数,利用这点获取所有的位置.例如: var str = "hello world,welcome!"; var arr = ...
- JMeter处理Cookie与Session
1.Cookie 添加方式:线程组-配置元件-HTTP Cookie 管理器,如下图: 2.Session 添加方式:线程组-前置处理器 -HTTP URL 重写修饰符,如下图: 有些tomcat的s ...
- Linux CentOS7/RHEL7关闭ctrl+alt+delete功能键
这是本人测试的经过,纯粹记录来看看,最终解决方法在最后面,中间讲的是遇到的一些坑,可以略过不看!! 本人操作经验,转载请表明出处:http://www.cnblogs.c ...
- 使用Asponse.Cell解决Excel科学计数法问题
//fileName --文件路径 public DataSet DataSetGetDataFromExcel(string fileName) { DataSet dataset = new Da ...
- DoTween基本使用
using UnityEngine; using System.Collections; using DG.Tweening; using UnityEngine.UI; public class D ...
- [Usaco 再次除草]
以后都用自己的号交吧 免得掉人品 Noip2016就是一个见证 一步一个脚印的刷 noip没把前两题稳拿就刷牛头.. bzoj1230 线段树打翻转标记,练手感 bzoj1231 状态压缩 预处理 ...
题目链接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 ...
CI持续集成 “我的TDD实践”系列之CI持续集成 写在前面: 我的TDD实践这几篇文章主要是围绕测试驱动开发所展开的,其中涵盖了一小部分测试理论,更多的则是关注工具的使用及环境的搭建,做到简单实践先 ...
Go - Revel框架介绍 https://github.com/robfig/revel http://robfig.github.io/revel/ web框架:revel 数据库:mongod ...
最近做了个项目用到了数据库登录,A登陆后把登录状态保,个人信息存在Session里,但是奇怪的是,只要有一个用户登录后在其他电脑上打开上述页面,则也显示A登录状态,注销也不管用了.以前还号的.求大神啊 ...
/* index.php 程序入口,用来构造sql(如查询,更新) config.php 配置参数(memcache,mysql) init.php 封装memcached操作(memca ...
indexOf方法可以传两个参数,第二个参数是传位置的参数,利用这点获取所有的位置.例如: var str = "hello world,welcome!"; var arr = ...
1.Cookie 添加方式:线程组-配置元件-HTTP Cookie 管理器,如下图: 2.Session 添加方式:线程组-前置处理器 -HTTP URL 重写修饰符,如下图: 有些tomcat的s ...
这是本人测试的经过,纯粹记录来看看,最终解决方法在最后面,中间讲的是遇到的一些坑,可以略过不看!! 本人操作经验,转载请表明出处:http://www.cnblogs.c ...
//fileName --文件路径 public DataSet DataSetGetDataFromExcel(string fileName) { DataSet dataset = new Da ...
using UnityEngine; using System.Collections; using DG.Tweening; using UnityEngine.UI; public class D ...
以后都用自己的号交吧 免得掉人品 Noip2016就是一个见证 一步一个脚印的刷 noip没把前两题稳拿就刷牛头.. bzoj1230 线段树打翻转标记,练手感 bzoj1231 状态压缩 预处理 ...