惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
月光博客
月光博客
IT之家
IT之家
B
Blog RSS Feed
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
博客园_首页
B
Blog
V
V2EX
腾讯CDC
Vercel News
Vercel News
量子位
Microsoft Security Blog
Microsoft Security Blog

OhYee 博客

小鹏辅助驾驶测评|OhYee 博客 小鹏非支持手机开启自动解锁|OhYee 博客 使用函数计算实现 301 重定向|OhYee 博客 针对 HTML 内容使用 Ant Design 图片弹框|OhYee 博客 博客进程泄露及僵尸进程解决|OhYee 博客 蓝易云服务器体验|OhYee 博客 SSH 调起本地 VSCode|OhYee 博客 【2022 秋招内推】阿里云后端研发工程师|OhYee 博客 使用函数计算获取 IP 地址信息|OhYee 博客 正确获取客户端 IP/HTTP Header 也可能重复|OhYee 博客 评测 Oculus Quest2 及 BigScreen|OhYee 博客 NextJS 热重载保留状态|OhYee 博客 如何优雅地贴 gist 代码|OhYee 博客 Linux 精细化文件权限|OhYee 博客 VSCode 容器开发环境|OhYee 博客 Clash 的不兼容更新排查|OhYee 博客 Zeek 导出 PCAP|OhYee 博客 记一次 ssh 配置问题|OhYee 博客 Git Commit 规范化工具|OhYee 博客 谈谈《星之卡比-探索发现》|OhYee 博客 VSCode 快捷键绑定 Shell 命令|OhYee 博客 ASN.1 语法及 X.509 证书格式解析解析|OhYee 博客 腾讯企业邮箱忽略 MX 记录发信|OhYee 博客 Chrome/Edge 标签组插件|OhYee 博客 【应届内推】阿里云后端研发工程师|OhYee 博客 损坏的 Typecho 备份处理为 JSON|OhYee 博客 VS Code VIM 插件高效使用|OhYee 博客 SSH 正反向代理|OhYee 博客 Let's Encrypt 根证书过期引发的问题|OhYee 博客 OpenWRT 忽略内核依赖|OhYee 博客
HDU 5983.Pocket Cube(2016 CCPC 青岛 B)|
2017-01-13 · via OhYee 博客

题目

{% raw %}

{% endraw %} The Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik’s Cube. The cube consists of 8 pieces, all corners. Each piece is labeled by a three dimensional coordinate (h, k, l) where h, k, l ∈ {0, 1}. Each of the six faces owns four small faces filled with a positive integer. For each step, you can choose a certain face and turn the face ninety degrees clockwise or counterclockwise. You should judge that if one can restore the pocket cube in one step. We say a pocket cube has been restored if each face owns four same integers.

{% raw %}


{% endraw %}

The first line of input contains one integer N(N ≤ 30) which is the number of test cases.
For each test case, the first line describes the top face of the pocket cube, which is the common 2 × 2 face of pieces
labelled by (0, 0, 1),(0, 1, 1),(1, 0, 1),(1, 1, 1). Four integers are given corresponding to the above pieces.
The second line describes the front face, the common face of (1, 0, 1),(1, 1, 1),(1, 0, 0),(1, 1, 0). Four integers are
given corresponding to the above pieces.
The third line describes the bottom face, the common face of (1, 0, 0),(1, 1, 0),(0, 0, 0),(0, 1, 0). Four integers are
given corresponding to the above pieces.
The fourth line describes the back face, the common face of (0, 0, 0),(0, 1, 0),(0, 0, 1),(0, 1, 1). Four integers are
given corresponding to the above pieces.
The fifth line describes the left face, the common face of (0, 0, 0),(0, 0, 1),(1, 0, 0),(1, 0, 1). Four integers are given
corresponding to the above pieces.
The six line describes the right face, the common face of (0, 1, 1),(0, 1, 0),(1, 1, 1),(1, 1, 0). Four integers are given
corresponding to the above pieces.
In other words, each test case contains 24 integers a, b, c to x. You can flat the surface to get the surface development
as follows.

+ - + - + - + - + - + - +  
| q | r | a | b | u | v |  
+ - + - + - + - + - + - +  
| s | t | c | d | w | x |  
+ - + - + - + - + - + - +  
        | e | f |  
        + - + - +  
        | g | h |  
        + - + - +  
        | i | j |  
        + - + - +  
        | k | l |  
        + - + - +  
        | m | n |  
        + - + - +  
        | o | p |  
        + - + - +  

{% raw %}


{% endraw %}

For each test case, output YES if can be restored in one step, otherwise output NO.

{% raw %}




{% endraw %}

4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
6 6 6 6
1 1 1 1
2 2 2 2
3 3 3 3
5 5 5 5
4 4 4 4
1 4 1 4
2 1 2 1
3 2 3 2
4 3 4 3
5 5 5 5
6 6 6 6
1 3 1 3
2 4 2 4
3 1 3 1
4 2 4 2
5 5 5 5
6 6 6 6

{% raw %}


{% endraw %}

YES
YES
YES
NO

{% raw %}




{% endraw %} # 题解 题意很容易理解,就是对一个二阶魔方,判断其是否能在一步内还原. 如果会还原三阶魔方,应该很容易就能理解. 经过分析,其实只有7种情况 1种是初始情况就是还原的,另外对于每一面分别向两个方向转一次.

比较稳妥的写法是直接把转后的位置顺序写出来,然后按照这个顺序查询是否存在不合法的情况.
(一定要注意不要写错!!!)

另外,需要额外注意,必须要满足6种颜色每种颜色4个

代码

```cpp Pocket Cube https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份 /*// #define debug #include

//*/ #include #include #include #include using namespace std;

int cube[24];

int list[7][24] = {
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23},
{0,5,2,7,4,9,6,11,8,13,10,15,12,1,14,3,16,17,18,19,22,20,23,21},
{0,13,2,15,4,1,6,3,8,5,10,7,12,9,14,11,16,17,18,19,21,23,20,22},
{20,21,2,3,4,5,6,7,8,9,16,17,12,13,14,15,0,1,18,19,10,11,22,23},
{16,17,2,3,4,5,6,7,8,9,20,21,12,13,14,15,10,11,18,19,0,1,22,23},
{2,0,3,1,22,20,6,7,8,9,10,11,12,13,19,17,16,4,18,5,14,21,15,23},
{1,3,0,2,17,19,6,7,8,9,10,11,12,13,20,22,16,15,18,14,4,21,5,23}
};

int check[24]={16,17,0,1,20,21,18,19,2,3,22,23,4,5,6,7,8,9,10,11,12,13,14,15};

map<int,int> m;
void solve() {
m.clear();
int pos = 0;
int num[24];
memset(num, 0, sizeof(num));

for (int i = 0; i < 6; i++){
    for (int j = 0; j < 4; j++) {
        int t;
        cin >> t;
        cube[i * 4 + j] = t;
        if (!m.count(t))
            m.insert(make_pair(t, pos++));
        num[m[t]]++;
    }
}

// cout<<"Cube:"<<endl;
// for(int i=0;i<24;i++)
//     cout<<cube[i]<<" ";
// cout<<endl;

//必须是6种颜色,并且每种4个

bool ok = true;
for (int i = 0; i < 6 && ok; i++)
    if (num[i] != 4)
        ok = false;

if (ok) {
    ok = false;

    for (int i = 0; i < 7 && !ok; i++) {
        //分别按照7种情况判断是否能够还原

        // cout << "Case" << i << endl;
        // for(int j=0;j<6;j++)
        //     printf("%3d",cube[list[i][check[j]]]);
        // cout<<endl;
        // for(int j=6;j<12;j++)
        //     printf("%3d",cube[list[i][check[j]]]);
        // cout<<endl;
        // for(int j=0;j<6;j++)
        //     printf("      %3d%3d\n",cube[list[i][check[12+j*2]]],cube[list[i][check[12+j*2+1]]]);
        // cout<<endl;
        

        bool flag = true;
        for (int j = 0; j < 6 && flag; j++) {
            if (cube[list[i][4 * j + 0]] != cube[list[i][4 * j + 1]] ||
                cube[list[i][4 * j + 0]] != cube[list[i][4 * j + 2]] ||
                cube[list[i][4 * j + 0]] != cube[list[i][4 * j + 3]])
                flag = false;
        }
        if (flag)
            ok = true;
    }
}
cout << (ok ? "YES" : "NO") << endl;

}

int main() {
#ifdef debug
freopen("in.txt", "r", stdin);
int START = clock();
#endif

int T;
cin >> T;
while (T--)
    solve();

#ifdef debug
printf("Time:%.3f s.\n", double(clock() - START) / CLOCKS_PER_SEC);
#endif
return 0;
}

</div></div>