Codeforces Round #265 (Div. 2)D(判断立方体)

B. Restore Cube
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers — coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.

When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.

Input

Each of the eight lines contains three space-separated integers — the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.

Output

If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers — the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.

If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.

Sample test(s)
input
0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
output
NO

题意:给出八个三维的点,然后可以将每个点的三维坐标任意交换位置(只能是点内,不能是点间),问你最后能不能构成一个正方体

思路:这题我也是看错了题目,把立方体理解为了长方体= =

            这题显然可以暴搜,然后判断是否有一种状态可以构成立方体

            这么这题就转化为了给出8个点,判断是否能构成立方体

            显然比较巧妙的方法是枚举每个点,然后算出这个点与其它7个点的距离

            然后找出3个最小的距离(可以理解为长宽高),因为是立方体,所以这3个距离一定要相等
 
            然后相等还不够,还要判断与这3个距离对应的边是否两两垂直

            而且对于每个点算出的与其它7个点的最短距离要相等,然后就没啥了

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         using namespace std; const long long INF = (long long)1e18; typedef long long ll; int x[8][3]; ll y[8][3]; ll ve[8]; void dfs(int cent) { if(cent==8) { ll temp=-1; for(int i=0;i<8;++i) { ll maxi=INF; int id[4]; id[0]=id[1]=id[2]=id[3]=-1; for(int j=0;j<8;++j) { if(j==i)continue; ve[j]=0; for(int k=0;k<3;k++) { y[j][k]=x[j][k]-x[i][k]; ve[j]+=y[j][k]*y[j][k]; } if(maxi>ve[j]) { maxi=ve[j]; id[0]=j; id[1]=-1; id[2]=-1; id[3]=-1; } else if(maxi==ve[j]) { id[3]=id[2]; id[2]=id[1]; id[1]=id[0]; id[0]=j; } } if(id[3]!=-1||id[2]==-1||id[1]==-1||id[0]==-1)return; if(maxi==0)return; if(temp==-1)temp=maxi; if(temp!=maxi)return; if(y[id[2]][0]*y[id[1]][0]+y[id[2]][1]*y[id[1]][1]+y[id[2]][2]*y[id[1]][2]!=0)return; if(y[id[2]][0]*y[id[0]][0]+y[id[2]][1]*y[id[0]][1]+y[id[2]][2]*y[id[0]][2]!=0)return; if(y[id[1]][0]*y[id[0]][0]+y[id[1]][1]*y[id[0]][1]+y[id[1]][2]*y[id[0]][2]!=0)return; } puts("YES"); for(int i=0;i<8;i++) { printf("%d %d %d\n",x[i][0],x[i][1],x[i][2]); } exit(0); return; } sort(x[cent],x[cent]+3); do{ dfs(cent+1); } while(next_permutation(x[cent],x[cent]+3)); } int main() { for(int i=0;i<8;i++) scanf("%d%d%d",&x[i][0],&x[i][1],&x[i][2]); dfs(1); puts("NO"); return 0; } 
       
      
      
     
     
    
    
   
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
校园失物招领系统管理系统按照操作主体分为管理员和用户。管理员的功能包括字典管理、论坛管理、公告信息管理、失物招领管理、失物认领管理、寻物启示管理、寻物认领管理、用户管理、管理员管理。用户的功能等。该系统采用了Mysql数据库,Java语言,Spring Boot框架等技术进行编程实现。 校园失物招领系统管理系统可以提高校园失物招领系统信息管理问题的解决效率,优化校园失物招领系统信息处理流程,保证校园失物招领系统信息数据的安全,它是一个非常可靠,非常安全的应用程序。 ,管理员权限操作的功能包括管理公告,管理校园失物招领系统信息,包括失物招领管理,培训管理,寻物启事管理,薪资管理等,可以管理公告。 失物招领管理界面,管理员在失物招领管理界面中可以对界面中显示,可以对失物招领信息的失物招领状态进行查看,可以添加新的失物招领信息等。寻物启事管理界面,管理员在寻物启事管理界面中查看寻物启事种类信息,寻物启事描述信息,新增寻物启事信息等。公告管理界面,管理员在公告管理界面中新增公告,可以删除公告。公告类型管理界面,管理员在公告类型管理界面查看公告的工作状态,可以对公告的数据进行导出,可以添加新公告的信息,可以编辑公告信息,删除公告信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值