zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    从键盘输入一串数据,以“exit"结束输入,且输出数据。
    判断指定盘符下文件夹是否存在
    java 输出图形
    Object对象类
    java继承
    Java封装
    java环境搭建系列:JDK环境变量详细配置
    java环境搭建系列:JDK从下载安装到简单使用
    ORACLE常见错误代码的分析与解决
    Java与C++面向对象不同点
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/6407631.html
Copyright © 2011-2022 走看看