HDU 5983 Pocket Cube(模拟)

news/2024/7/2 1:22:31 标签: 模拟

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5983

题意:给你个魔方,问能否一步之内把他还原。哎。。。写了半天,标号后一步步来,我真tm菜。

#include <cstdio>
#include <map>
#define ll long long
using namespace std;
int a[30];
map<int,int> mp;
int rot[6][24]={
{1,2,3,4,9,10,11,12,21,23,7,8,5,6,17,19,18,20,13,14,15,16,22,24},
{1,2,3,4,9,10,11,12,18,20,7,8,5,6,22,24,21,23,13,14,15,16,17,19},
{5,6,7,8,13,14,15,16,1,2,23,24,9,10,21,22,11,12,19,20,17,18,3,4},
{5,6,7,8,13,14,15,16,1,2,19,20,21,22,3,4,23,24,11,12,9,10,17,18},
{17,18,19,20,21,22,23,24,5,7,2,4,9,11,6,8,13,15,10,12,1,3,14,16},
{17,18,19,20,21,22,23,24,1,3,6,8,5,7,10,12,9,11,14,16,13,15,2,4}
};
int judge(int cur){
    for(int i=0;i<24;i+=4){
        for(int j=1;j<4;j++){
            if(a[rot[cur][i]]!=a[rot[cur][i+j]]){
            return 0;
            }
        }
    }
    return 1;
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        bool flag=1;
        for(int i=1;i<=24;i++){
          scanf("%d",&a[i]);
        }
        for(int i=1;i<=24;i+=4){
          for(int j=1;j<4;j++){
             if(a[i]!=a[i+j]){
                flag=0;
                break;
             }
          }
        }
        if(flag){
            puts("YES");
            continue;
        }
        for(int i=0;i<6;i++){
            if(judge(i)){
                flag=1;
                break;
            }
        }
        puts(flag?"YES":"NO");
    }
    return 0;
}

 


http://www.niftyadmin.cn/n/1846973.html

相关文章

递归问题(2020-12-21)

递归问题 1、⼀个有 n 级的台阶&#xff0c;⼀次可以⾛ 1 级、2 级或 3 级&#xff0c;问⾛完 n 级台阶有多少种⾛法&#xff1f; public static int test(int n) {if(n < 0) {return 0;}else if(n 0) {return 1;}else {return test(n-1)test(n-2)test(n-3);} }2.古典问题…

堆排-元素去重-查找问题

堆排序与元素去重及查找问题 1、堆排序与元素去重 package com.m.sort;import java.util.Arrays; import java.util.Random;public class Test2 {public static void main(String[] args) {Random random new Random();int[] arr new int[12];for (int i 0; i < arr.le…

线程死锁_hashMap参数

多线程 1、模拟一个线程死锁 package com.m.sort;public class Test2 {private static final Object obj1 new Object();private static final Object obj2 new Object();public static void main(String[] args) {new Thread(()->{synchronized (obj1){try {Thread.sle…

进制转换_负数的补码

补码: 假设当前时针指向8点&#xff0c;而准确时间是6点&#xff0c;调整时间可有以下两种拨法&#xff1a;一种是倒拨2小时&#xff0c; 即8-26&#xff1b;另一种是顺拨10小时&#xff0c;8101266&#xff0c;即8-2810812-2(mod 12)&#xff0e;在12为模的系统里&#xff0c;…

时间定律与学习规律

时间定律与学习规律 时间定律 package com.m;import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.util.Calendar; import java.util.Date;public class Test {//1000小时&#xff0c;定律;//每天8小时&#xff0c;需要125天。//每个月30天,需要…

pta甲级 1127 ZigZagging on a Tree (30分)

链接&#xff1a;https://pintia.cn/problem-sets/994805342720868352/problems/994805349394006016 题意&#xff1a;给出n个点的二叉树的中序遍历序列和后序遍历序列。按“Z”型输出层序遍历序列。 思路&#xff1a;直接大模拟&#xff0c;建树硬怼。详情看注释。 #includ…

插入排序与数组查重

插入排序与数组查重 //插入排序public static void main(String[] args) {Random random new Random();int [] arr new int[12];for (int i 0; i < arr.length; i) {arr[i] random.nextInt(12)8;}System.out.println(Arrays.toString(arr));chaSort(arr);System.out.pri…

pta 甲级1119 Pre- and Post-order Traversals (30分)

链接&#xff1a;https://pintia.cn/problem-sets/994805342720868352/problems/994805353470869504 题意&#xff1a;给出二叉树的前序、后序遍历序列&#xff0c;能否唯一确定一棵树&#xff1f;输出中序遍历序列。 思路&#xff1a;能否确定一棵树关键在于是否有只有一个孩…