Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个1k的代码附有解释供交流 哈哈哈哈

Posted by heroyjz at 2010-08-19 09:55:47 on Problem 1835
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
int dir[6][4]={1,2,4,5,3,2,0,5,3,4,0,1,2,1,5,4,0,2,3,5,1,0,4,3};  //dir[6][4] 是构造以i为头顶方向的6个顺时针遍历面
int dist[6]={0,0,0,0,0,0};  //保存每个方向上走的距离
int main()
{
	string headfor[6]={"forward","right","back","left","up","down"};
	int n,num,i,step,j,turn,locate,temp;
	string direction;
	cin>>n;
	while(n--)
	{
		memset(dist,0,sizeof(dist));
		cin>>num;
		int Dir_now=0;  //当前方向
		int belong=2;   //头顶方向
		for(i=0;i<num;i++)
		{
			cin>>direction>>step;
			for(j=0;j<6;j++)
			{
				if(direction.compare(headfor[j])==0)
				{turn=j;break;}
			}
			if(turn<4)  //前后左右按照顺时针遍历,此时“上方”不变
			{
				for(j=0;j<4;j++)
					if(dir[belong][j]==Dir_now)
					{locate=j;break;}
				Dir_now=dir[belong][(locate+turn)%4];
			}
			else if(turn==4)  //向上走,即原来的上方变前方,后方变头顶
			{
				temp=(Dir_now+3)%6;
				Dir_now=belong;
				belong=temp;
			}
			else   //向下走,即原来的下方变前方,头顶变成后方
			{
				temp=(belong+3)%6;
				belong=Dir_now;
				Dir_now=temp;
				
			}
			dist[Dir_now]+=step;
		}
		cout<<dist[0]-dist[3]<<" "<<dist[1]-dist[4]<<" "<<dist[2]-dist[5]<<" "<<Dir_now<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator