poj解题报告——1835

9 篇文章 0 订阅

        一个立体几何的问题,划归成模拟量做,一共是六个方向

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值