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; }
相关文章推荐
- 一位ACMer过来人的心得
- ${pageContext.request.contextPath} JSP取得绝对路径
- 北风网66jquery
- Android 判断网络连接情况
- AngularJs解决方案笔记(1)
- jsoncpp在linux下的配置
- Java死锁以及查看
- C++静态库与动态库
- telnetlib 中各种 read 函数的意义
- [LeetCode]Summary Ranges
- ejs笔记
- ROM移植出现的java.lang.NullPointerException解决
- uva:10700 - Camel trading(贪婪)
- 解决无法打开文件名称是中文的
- 遍历Map集合的方法
- Vijos P1836HYS与七夕节大作战
- 宏定义,条件编译,共用体,位运算,位域
- ubuntu下更改ip地址
- Qt MVC学习 模型子类化参考
- 2015计算之道第三场第二题