zoukankan      html  css  js  c++  java
  • AC日记——魔方 洛谷 P2007

    魔方

    思路:

      模拟;

    代码:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    struct MFType {
        int ai[4][4];
    };
    struct MFType ci[7];
    
    int len;
    
    char done[500],ch[10];
    
    /*
    
    1.front
    2.back
    3.left
    4.right
    5.top
    6.under
    
    */
    
    void OperationType_right_turning90()
    {
        MFType *now=&ci[4],tmp=ci[4];
        now->ai[1][1]=tmp.ai[3][1];
        now->ai[1][2]=tmp.ai[2][1];
        now->ai[1][3]=tmp.ai[1][1];
        now->ai[2][1]=tmp.ai[3][2];
        now->ai[2][3]=tmp.ai[1][2];
        now->ai[3][1]=tmp.ai[3][3];
        now->ai[3][2]=tmp.ai[2][3];
        now->ai[3][3]=tmp.ai[1][3];
        now=&ci[1],tmp=ci[1];
        MFType *pos=&ci[6];
        now->ai[1][3]=pos->ai[1][3];
        now->ai[2][3]=pos->ai[2][3];
        now->ai[3][3]=pos->ai[3][3];
        now=&ci[6],pos=&ci[2];
        now->ai[1][3]=pos->ai[1][3];
        now->ai[2][3]=pos->ai[2][3];
        now->ai[3][3]=pos->ai[3][3];
        now=&ci[2],pos=&ci[5];
        now->ai[1][3]=pos->ai[1][3];
        now->ai[2][3]=pos->ai[2][3];
        now->ai[3][3]=pos->ai[3][3];
        now=&ci[5],pos=&tmp;
        now->ai[1][3]=pos->ai[1][3];
        now->ai[2][3]=pos->ai[2][3];
        now->ai[3][3]=pos->ai[3][3];
    }
    
    void OperationType_right_turningback90()
    {
        MFType *now=&ci[4],tmp=ci[4];
        now->ai[1][1]=tmp.ai[1][3];
        now->ai[1][2]=tmp.ai[2][3];
        now->ai[1][3]=tmp.ai[3][3];
        now->ai[2][1]=tmp.ai[1][2];
        now->ai[2][3]=tmp.ai[3][2];
        now->ai[3][1]=tmp.ai[1][1];
        now->ai[3][2]=tmp.ai[2][1];
        now->ai[3][3]=tmp.ai[3][1];
        now=&ci[1],tmp=ci[1];
        MFType *pos=&ci[5];
        now->ai[1][3]=pos->ai[1][3];
        now->ai[2][3]=pos->ai[2][3];
        now->ai[3][3]=pos->ai[3][3];
        now=&ci[5],pos=&ci[2];
        now->ai[1][3]=pos->ai[1][3];
        now->ai[2][3]=pos->ai[2][3];
        now->ai[3][3]=pos->ai[3][3];
        now=&ci[2],pos=&ci[6];
        now->ai[1][3]=pos->ai[1][3];
        now->ai[2][3]=pos->ai[2][3];
        now->ai[3][3]=pos->ai[3][3];
        now=&ci[6],pos=&tmp;
        now->ai[1][3]=pos->ai[1][3];
        now->ai[2][3]=pos->ai[2][3];
        now->ai[3][3]=pos->ai[3][3];
    }
    
    void OperationType_top_turning90()
    {
        MFType *now=&ci[5],tmp=ci[5];
        now->ai[1][1]=tmp.ai[3][1];
        now->ai[1][2]=tmp.ai[2][1];
        now->ai[1][3]=tmp.ai[1][1];
        now->ai[2][1]=tmp.ai[3][2];
        now->ai[2][3]=tmp.ai[1][2];
        now->ai[3][1]=tmp.ai[3][3];
        now->ai[3][2]=tmp.ai[2][3];
        now->ai[3][3]=tmp.ai[1][3];
        now=&ci[1],tmp=ci[1];
        MFType *pos=&ci[3];
        now->ai[1][1]=pos->ai[1][1];
        now->ai[1][2]=pos->ai[1][2];
        now->ai[1][3]=pos->ai[1][3];
        now=&ci[3],pos=&ci[2];
        now->ai[1][1]=pos->ai[1][1];
        now->ai[1][2]=pos->ai[1][2];
        now->ai[1][3]=pos->ai[1][3];
        now=&ci[2],pos=&ci[4];
        now->ai[1][1]=pos->ai[1][1];
        now->ai[1][2]=pos->ai[1][2];
        now->ai[1][3]=pos->ai[1][3];
        now=&ci[4],pos=&tmp;
        now->ai[1][1]=pos->ai[1][1];
        now->ai[1][2]=pos->ai[1][2];
        now->ai[1][3]=pos->ai[1][3];
    }
    
    void OperationType_top_turningback90()
    {
        MFType *now=&ci[5],tmp=ci[5];
        now->ai[1][1]=tmp.ai[1][3];
        now->ai[1][2]=tmp.ai[2][3];
        now->ai[1][3]=tmp.ai[3][3];
        now->ai[2][1]=tmp.ai[1][2];
        now->ai[2][3]=tmp.ai[3][2];
        now->ai[3][1]=tmp.ai[1][1];
        now->ai[3][2]=tmp.ai[2][1];
        now->ai[3][3]=tmp.ai[3][1];
        now=&ci[1],tmp=ci[1];
        MFType *pos=&ci[4];
        now->ai[1][1]=pos->ai[1][1];
        now->ai[1][2]=pos->ai[1][2];
        now->ai[1][3]=pos->ai[1][3];
        now=&ci[4],pos=&ci[2];
        now->ai[1][1]=pos->ai[1][1];
        now->ai[1][2]=pos->ai[1][2];
        now->ai[1][3]=pos->ai[1][3];
        now=&ci[2],pos=&ci[3];
        now->ai[1][1]=pos->ai[1][1];
        now->ai[1][2]=pos->ai[1][2];
        now->ai[1][3]=pos->ai[1][3];
        now=&ci[3],pos=&tmp;
        now->ai[1][1]=pos->ai[1][1];
        now->ai[1][2]=pos->ai[1][2];
        now->ai[1][3]=pos->ai[1][3];
    }
    
    void debug()
    {
        printf("
    ");
        for(int i=1;i<=6;i++)
        {
            printf("%d
    ",i);
            for(int j=1;j<=3;j++)
            {
                for(int v=1;v<=3;v++) printf("%d",ci[i].ai[j][v]);
                printf("
    ");
            }
            printf("
    ");
        }
        printf("
    ");
    }
    
    int main()
    {
        freopen("cube.in","r",stdin);
        freopen("cube.out","w",stdout);
        scanf("%s",done),len=strlen(done);
        for(int i=1;i<=6;i++)
        {
            for(int j=1;j<=3;j++)
            {
                scanf("%s",ch);
                for(int v=1;v<=3;v++) ci[i].ai[j][v]=ch[v-1]-'0';
            }
        }
    //    debug();
        for(int i=0;i<len;i++)
        {
            if(done[i]=='1') OperationType_right_turning90();
            else if(done[i]=='2') OperationType_right_turningback90();
            else if(done[i]=='3') OperationType_top_turning90();
            else if(done[i]=='4') OperationType_top_turningback90();
    //        debug();
        }
        for(int i=1;i<=6;i++)
        {
            for(int j=1;j<=3;j++)
            {
                for(int v=1;v<=3;v++) printf("%d",ci[i].ai[j][v]);
                printf("
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    PHP 多参数方法的重构
    PHP cURL库函数抓取页面内容
    PHP下载远程文件到指定目录
    PHP生成特定长度的纯字母字符串
    PHP提取奇数或偶数下标元素
    Java中的clone()----深复制,浅复制
    LeetCode题解 343.Integer Break
    MySQL学习笔记(四):存储引擎的选择
    存储过程优缺点
    MySQL学习笔记(三):常用函数
  • 原文地址:https://www.cnblogs.com/IUUUUUUUskyyy/p/6912748.html
Copyright © 2011-2022 走看看