codeforces Restore Cube(暴力枚举)
/*
题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!),
问是否可以还原出一个立方体的坐标,注意这一句话:
The numbers in the i-th output line must be a permutation of the numbers in i-th input line! 思路:
我们只要对输入的每一行数据进行枚举每一个排列, 然后检查时候能构成立方体就好了!
检查立方体:找到最小的边长的长度 l, 统计边长为l, sqrt(2)*l, sqrt(3)*l的边长
条数,如果恰好分别为12, 12, 4那么就是立方体了...
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; typedef long long LL; LL num[][], d[]; LL dis(int i, int j){
return (num[i][]-num[j][])*(num[i][]-num[j][]) +
(num[i][]-num[j][])*(num[i][]-num[j][]) +
(num[i][]-num[j][])*(num[i][]-num[j][]);
} void out(){
for(int i=; i<; ++i){
printf("%lld", num[i][]);
for(int j=; j<; ++j)
printf(" %lld", num[i][j]);
printf("\n");
}
} int vis[][]; bool check(){
int cnt=;
int cnt1=, cnt2=, cnt3=;
LL L=(1LL)<<;
memset(vis, , sizeof(vis));
for(int i=; i<; ++i)
for(int j=; j<; ++j)
if(i!=j && !vis[i][j] && !vis[j][i]){
d[cnt++]=dis(i, j);
vis[i][j]=vis[j][i]=;
if(L>d[cnt-])
L=d[cnt-];
}
if(L==) return false;
for(int i=; i<cnt; ++i)
if(d[i] == L) cnt1++;
else if(d[i] == *L) cnt2++;
else if(d[i] == *L) cnt3++;
if(cnt1== && cnt2== && cnt3==) return true;
return false;
} bool dfs(int cur){
if(cur>=) return false;
sort(num[cur], num[cur]+);//排序
do{
if(check()){
printf("YES\n");
out();
return true;
}
if(dfs(cur+)) return true;//得到当前的全排列之后,继续向下寻找
}while(next_permutation(num[cur], num[cur]+));//枚举这一个行的每一个全排列
return false;
} int main(){
for(int i=; i<; ++i)
for(int j=; j<; ++j)
scanf("%lld", &num[i][j]);
if(!dfs())
printf("NO\n");
return ;
}
codeforces Restore Cube(暴力枚举)的更多相关文章
- Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)
The only difference between easy and hard versions is a number of elements in the array. You are giv ...
- codeforces 466c(暴力枚举)
题目链接 思路如下 *题意: 给定一个序列,问有多少种方案可以将此序列分割成3个序列元素和完全相同的子序列.(子序列不能为空).即问有多少个点对(i,j)满足a[1]+-+a[i-1]=a[i]+a[ ...
- Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...
- Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举
B. Covered Path Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断
http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- codeforces 464B Restore Cube
题目链接 给8个点, 判断这8个点能否组成一个正方体, 如果能, 输出这8个点. 同一个点的x, y, z可以交换. 每一个点有6种排列方式, 一个8个点, 暴力枚举出所有排列方式然后判断能否组成正方 ...
随机推荐
- Android SQLite3工具常用命令行总结
Android SDK的tools目录下提供了一个sqlite3.exe工具,这是一个简单的sqlite数据库管理工具.开发者可以方便的使用其对sqlite数据库进行命令行的操作. 程序运行生成的*. ...
- Level shifting a +/- 2.5V signal to 0 - 5V
Google : Op-Amp Level Shifter Level shifting a +/- 2.5V signal to 0 - 5V I have a front end module t ...
- Linux 下安装Samba 文件共享服务器
samba文件共享服务可以让linux和linux系统.linux和windows系统之间共享文件 服务查询 默认情况下,Linux系统在默认安装中已经安装了Samba服务包的一部分,为了对整个过程有 ...
- http协议读书笔记3-Web服务器
一.web服务器的实现 web服务器逻辑实现了HTTP协议和相关的TCP连接处理,管理着web资源,并负责提供Web服务器的管理功能.web服务器逻辑和操作系统共同负责管理TCP连接.底层操作系统负责 ...
- leveldb - menifest文件格式
MANIFEST文件是Level DB的元信息文件,它里面的格式是leveldb的Log格式,一个menifest是一个record: void VersionEdit::EncodeTo(std:: ...
- 精通MVC网站、MVVM开发模式、Razor语法
http://www.cnblogs.com/powertoolsteam/p/MVC_one.html ASP.NET MVC (一)——深入理解ASP.NET MVC 以下是ASP.NET MVC ...
- chrome start.js报错
是由 chrome 插件 “电脑管家广告过滤” 引起的 并且,在用户电脑上还出现了这个插件拦截正常请求的情况 如果同时报以下错误: Uncaught TypeError: Cannot read pr ...
- 【网络编程】——windows socket 编程
测试demo #include <winsock2.h> #include <stdio.h> #include <string.h> #include <s ...
- Django 新人开发的十个注意点
总结一下 Django开发中,注意的事项,特别是新人,由于水平有限,也只能到这个层次,更多模式思想性的东西,还得在开发中慢慢体会. 1.各个APP独立,做到项目的模块分明.说的有点大,列几个列子优先 ...
- ubuntu-15.04-server-i386.iso 安装 Oracle 11gR2 数据库
特点: 需要重新安装老版本的 libaio1_0.3.109-2ubuntu?_i386.deb.默认的libaio库有问题,和其默认libaio的编译方式有关! 默认的gcc 4.9 需要使用 -W ...