您的位置:首页 > 其它

poj解题报告——1835

2015-07-19 09:47 323 查看
一个立体几何的问题,划归成模拟量做,一共是六个方向

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int arr[6][6];
char direction[20];
void init()
{
arr[0][1]=2;arr[0][2]=4;arr[0][4]=5;arr[0][5]=1;
arr[1][2]=0;arr[1][5]=3;arr[1][0]=5;arr[1][3]=2;
arr[2][0]=1;arr[2][3]=4;arr[2][1]=3;arr[2][4]=0;
arr[3][1]=5;arr[3][4]=2;arr[3][2]=1;arr[3][5]=4;
arr[4][0]=2;arr[4][3]=5;arr[4][2]=3;arr[4][5]=0;
arr[5][4]=3;arr[5][1]=0;arr[5][0]=4;arr[5][3]=1;
}
void cal(int &x,int &y,int &z,int pos,int step)
{
if(pos==0)
x+=step;
else if(pos==1)
y+=step;
else if(pos==2)
z+=step;
else if(pos==3)
x-=step;
else if(pos==4)
y-=step;
else if(pos==5)
z-=step;
}
int main()
{
init();
int T;
scanf("%d",&T);
int n,x,y,z,pos,step,head;
while(T--)
{
scanf("%d",&n);
x=y=z=pos=0;
head=2;
while(n--)
{
scanf("%s %d",direction,&step);
if(direction[0]=='b')
{
pos=(pos+3)%6;
}
else if(direction[0]=='l')
{
pos=arr[pos][head];
}
else if(direction[0]=='r')
{
pos=((arr[pos][head])+3)%6;
}
else if(direction[0]=='u')
{
int t=pos;
pos=head;
head=(t+3)%6;
}
else if(direction[0]=='d')
{
int t=pos;
pos=(head+3)%6;
head=t;
}
cal(x,y,z,pos,step);
}
printf("%d %d %d %d\n",x,y,z,pos);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: