转骰子
标题:转骰子 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
骰子是一个立方体,每个面一个数字,初始为左1,右2,前3(观察者方向),后4,上5,下6,用123456表示这个状态,放置到平面上,可以向左翻转(用L表示向左翻转1次),可以向右翻转(用R表示向右翻转1次),可以向前翻转(用F表示向前翻转1次),可以向后翻转(用B表示向后翻转1次),可以逆时针旋转(用A表示逆时针旋转90度),可以顺时针旋转(用C表示顺时针旋转90度),现从123456这个初始状态开始,根据输入的动作序列,计算得到最终的状态。
骰子的初始状态和初始状态转动后的状态如图所示
kai = ['1', '2', '3', '4', '5', '6']
s = input()
for i in s:
if i == 'L':
uu = [kai[0], kai[4], kai[1], kai[5]]
kai[0] = uu[1]
kai[4] = uu[2]
kai[1] = uu[3]
kai[5] = uu[0]
elif i == 'R':
uu = [kai[0], kai[4], kai[1], kai[5]]
kai[0] = uu[3]
kai[4] = uu[0]
kai[1] = uu[1]
kai[5] = uu[2]
elif i == 'F':
uu = [kai[2], kai[4], kai[3], kai[5]]
kai[2] = uu[1]
kai[4] = uu[2]
kai[3] = uu[3]
kai[5] = uu[0]
elif i == 'B':
uu = [kai[2], kai[4], kai[3], kai[5]]
kai[2] = uu[3]
kai[4] = uu[0]
kai[3] = uu[1]
kai[5] = uu[2]
elif i == 'A':
uu = [kai[0], kai[2], kai[1], kai[3]]
kai[0] = uu[3]
kai[2] = uu[0]
kai[1] = uu[1]
kai[3] = uu[2]
elif i == 'C':
uu = [kai[0], kai[2], kai[1], kai[3]]
kai[0] = uu[1]
kai[2] = uu[2]
kai[1] = uu[3]
kai[3] = uu[0]
print(''.join(kai))
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll p = 998244353;
int a[10];
int b[10];
int solve(int x,char s){
if(s=='R'){
if(x==5) x=1;
else if(x==2) x=5;
else if(x==1) x=6;
else if(x==6) x=2;
}
if(s=='L'){
if(x==5) x=2;
else if(x==2) x=6;
else if(x==1) x=5;
else if(x==6) x=1;
}
if(s=='B'){
if(x==3) x=6;
else if(x==5) x=3;
else if(x==4) x=5;
else if(x==6) x=4;
}
if(s=='F'){
if(x==3) x=5;
else if(x==5) x=4;
else if(x==4) x=6;
else if(x==6) x=3;
}
if(s=='C'){
if(x==1) x=3;
else if(x==3) x=2;
else if(x==2) x=4;
else if(x==4) x=1;
}
if(s=='A'){
if(x==1) x=4;
else if(x==3) x=1;
else if(x==2) x=3;
else if(x==4) x=2;
}
return a[x];
}
int main(){
for(int i=1;i<=6;i++) a[i]=i;
string s;
cin>>s;
for(int i=0;i<s.size();i++){
for(int j=1;j<=6;j++){
b[j]=solve(j,s[i]);
}
for(int j=1;j<=6;j++) a[j]=b[j];
}
for(int i=1;i<=6;i++) cout<<a[i];
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string str;
cin >> str;
vector<int> vv = {0,1,2,3,4,5,6};
for(int i = 0; i < str.size(); i++)
{
switch(str[i])
{
case 'L':
{
int a = vv[1];
vv[1] = vv[5];
vv[5] = vv[2];
vv[2] = vv[6];
vv[6] = a;
}
break;
case 'R':
{
int a = vv[1];
vv[1] = vv[6];
vv[6] = vv[2];
vv[2] = vv[5];
vv[5] = a;
}
break;
case 'F':
{
int a = vv[3];
vv[3] = vv[5];
vv[5] = vv[4];
vv[4] = vv[6];
vv[6] = a;
}
break;
case 'B':
{
int a = vv[3];
vv[3] = vv[6];
vv[6] = vv[4];
vv[4] = vv[5];
vv[5] = a;
}
break;
case 'A':
{
int a = vv[3];
vv[3] = vv[1];
vv[1] = vv[4];
vv[4] = vv[2];
vv[2] = a;
}
break;
case 'C':
{
int a = vv[3];
vv[3] = vv[2];
vv[2] = vv[4];
vv[4] = vv[1];
vv[1] = a;
}
break;
}
}
for(int i = 1; i < 7; i++)
cout<<vv[i];
return 0;
}

查看11道真题和解析