zoukankan      html  css  js  c++  java
  • UVA253 Cube painting(数学)

    题目链接

    分析:

    用的《训练指南》上的方法。详见P17.

    从6个面中选一个做顶面,再从剩下的4个面中选1个做正面,则此正方体唯一确定。

    需要枚举共6*4=24种。

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <string>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cstring>
    
    using namespace std;
    
    const int maxn = 1000;
    
    int _left[6] = {4, 0, 2, 3, 5, 1};
    int up[6] = {2, 1, 5, 0, 4, 3};
    
    char s1[maxn], s2[maxn], s[maxn];
    
    void rot(int *T, char *str) {
        char t[maxn];
        strcpy(t, str);
        for(int i=0; i<6; i++) str[i] = t[T[i]];
    }
    
    bool check() {
        char t[maxn];
        for(int i=0; i<6; i++) {
        strcpy(t, s1);
        if(i == 0) rot(up, t);
        else if(i == 1) { rot(_left, t); rot(up, t); }
        else if(i == 3) { rot(up, t); rot(up, t); }
        else if(i == 4) { rot(_left, t); rot(_left, t); rot(up, t); }
        else if(i == 5) { rot(_left, t); rot(_left, t); rot(_left, t); rot(up, t); }
        for(int i=0; i<4; i++) {
            rot(_left, t);
            if(strcmp(s2, t) == 0) return 1;
        }
        }
        
        return 0;
    }
    
    int main() {
    
        while(gets(s)) {
        for(int i=0; i<6; i++) s1[i] = s[i];
        s1[6] = '';
        
        for(int i=6; i<12; i++) s2[i-6] = s[i];
        s2[6] = '';
        
        if(check()) printf("TRUE
    ");
        else printf("FALSE
    ");
        }
        
        return 0;
    }
  • 相关阅读:
    JVM与Dalvik
    3G技术
    Android开发环境的搭建
    Android学习杂记
    JDK环境变量配置
    签名Android应用程序
    Android中Hardcoding String ……,should use @string/警告的处理
    命令行创建Android项目
    ElasticSearch为什么这么快
    多线程1--基础知识
  • 原文地址:https://www.cnblogs.com/tanhehe/p/3179699.html
Copyright © 2011-2022 走看看