UVaLive 3401 Colored Cubes (暴力)

题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同。

析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-5;
const int maxn = 20000 + 10;
const int mod = 1e6 + 10;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
  return r >= 0 && r < n && c >= 0 && c < m;
}
const int dice24[24][6] = {
{2, 1, 5, 0, 4, 3},
{2, 0, 1, 4, 5, 3},
{2, 4, 0, 5, 1, 3},
{2, 5, 4, 1, 0, 3},
{4, 2, 5, 0, 3, 1},
{5, 2, 1, 4, 3, 0},
{1, 2, 0, 5, 3, 4},
{0, 2, 4, 1, 3, 5},
{0, 1, 2, 3, 4, 5},
{4, 0, 2, 3, 5, 1},
{5, 4, 2, 3, 1, 0},
{1, 5, 2, 3, 0, 4},
{5, 1, 3, 2, 4, 0},
{1, 0, 3, 2, 5, 4},
{0, 4, 3, 2, 1, 5},
{4, 5, 3, 2, 0, 1},
{1, 3, 5, 0, 2, 4},
{0, 3, 1, 4, 2, 5},
{4, 3, 0, 5, 2, 1},
{5, 3, 4, 1, 2, 0},
{3, 4, 5, 0, 1, 2},
{3, 5, 1, 4, 0, 2},
{3, 1, 0, 5, 4, 2},
{3, 0, 4, 1, 5, 2},
};

map<string, int> mp;
int dice[10][10];
int ans;
int r[10];

int getId(const string &s){
  if(mp.count(s))  return mp[s];
  return mp[s] = mp.size();
}
int color[10][10];

void judge(){
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < 6; ++j)  color[i][dice24[r[i]][j]] = dice[i][j];
  int tot = 0;
  for(int i = 0; i < 6; ++i){
    int cnt[30];
    memset(cnt, 0, sizeof cnt);
    int mmax = 0;
    for(int j = 0; j < n; ++j)  mmax = max(mmax, ++cnt[color[j][i]]);
    tot += n - mmax;
  }
  ans = min(ans, tot);
}

void dfs(int d){
  if(d == n){ judge();  return ; }
  for(int i = 0; i < 24; ++i){
    r[d] = i;
    dfs(d+1);
  }
}

int main(){
  while(cin >> n && n){
    mp.clear();
    string s;
    for(int i  = 0; i < n; ++i)
      for(int j = 0; j < 6; ++j){
        cin >> s;
        dice[i][j] = getId(s);
      }
      ans = n * 6;
      r[0] = 0;
      dfs(1);
      cout << ans << endl;
  }
  return 0;
}
时间: 2024-12-18 03:33:43

UVaLive 3401 Colored Cubes (暴力)的相关文章

UVALIVE 3401 Colored Cubes

翻转立方体 #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string>

UVA 10733 - The Colored Cubes(Ploya)

UVA 10733 - The Colored Cubes 题目链接 题意:一个立方体.n种颜色,问能涂成多少不同立方体 思路:Ploya求解,正方体相应24种不同旋转一一计算出循环个数就可以.和 UVA 10601 - Cubes这题类似 代码: #include <stdio.h> #include <string.h> unsigned long long n; int main() { while (~scanf("%llu", &n) &

POJ2741 Colored Cubes

Description There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same. Two cubes are said to be id

uva 1352 Colored Cubes(枚举)

uva 1352 Colored Cubes There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same. Two cubes are sa

Gym 100299C &amp;&amp; UVaLive 6582 Magical GCD (暴力+数论)

题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点时,我们对gcd相同的只保留一个,那就是左端点最小的那个,只有这样才能保证是最大,然后删掉没用的. UVaLive上的数据有问题,比赛时怎么也交不过,后来去别的oj交就过了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&qu

A. The Fault in Our Cubes 暴力dfs

http://codeforces.com/gym/101257/problem/A 把它固定在(0,0, 0)到(2, 2, 2)上,每次都暴力dfs检查,不会超时的,因为规定在这个空间上,一不行,就会早早退出. 这样写起来比较好写. #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <

UVaLive 7461 Separating Pebbles (暴力)

题意:给出平面上的两类点,判断是否能画一条直线将两类点完全分割开来. 析:用暴力去枚举任意两点当作直线即可. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #inclu

UVA - 10733 The Colored Cubes (置换)

All 6 sides of a cube are to becoated with paint. Each side is is coated uniformly with one color. When a selectionof n different colors of paint is available, how many different cubes can youmake? Note that any two cubes are onlyto be called "differ

【poj2741】 Colored Cubes

http://poj.org/problem?id=2741 (题目链接) 这也是道神题.. 题意:给出n个骰子,每一面都有一种颜色,问最少更改多少个面的颜色可以使所有骰子通过旋转后完全相同. solution  设6个面的编号为1~6,从中选一个作为顶面,再选一个作为正面,那么其它面都可以确定(因为有对面的面也确定了),因此每个骰子有6*4=24种姿态,每种姿态对应一个全排列P,P[i]表示i所在的位置.所以我们手打这24种排列.  接下来看看如何暴力.我们考虑先枚举每个立方体的姿态(第一个作