首页 > 其他 > 详细

[POJ1835]宇航员<模拟>

时间:2020-02-10 21:19:39      阅读:74      评论:0      收藏:0      [点我收藏+]

链接:http://poj.org/problem?id=1835

题干太长我就不放描述了。

一道大模拟

看着就脑壳疼。

难点可能在于方向的确认上

要明确当前的头朝向和脸朝向,才能进行处理

一个小小坑可能算是up和down吧,不看图可能就觉得是直上直下了

里面所有的方向都是相对于当前脸的朝向的。

 

然后就是0对3 1对4 2对5 取相反可以+3再%6

然后就是一堆if

case也行,不过我那提交一直提示编译错误,改if就没了,不知道为啥

技术分享图片
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<utility>
#include<stack>
#include<cstdlib>
#define ll long long
#define inf 0x3fffffff
using namespace std;

int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
    while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
    return x*f;
}

void fre(){
     freopen("     .in","r",stdin);
     freopen("     .out","w",stdout);
}

int x,y,z,step,n,T;

void sec_main(int direct){
    if(direct==0)x+=step;
    if(direct==1)y+=step;
    if(direct==2)z+=step;
    if(direct==3)x-=step;
    if(direct==4)y-=step;
    if(direct==5)z-=step;
}

int main(){
    int head,dir,left,temp;
    T=read();
    while(T--){
        n=read();
        char s[20];
        head=2,dir=0,left=4,x=y=z=0;
        for(int i=0;i<n;++i){
            scanf("%s %d",s,&step);
            if(s[0]==b){
                dir=(dir+3)%6,left=(left+3)%6;
            }
            if(s[0]==l){
                temp=left,left=(dir+3)%6,dir=temp;
            }
            if(s[0]==r){
                temp=dir,dir=(left+3)%6,left=temp;
            }
            if(s[0]==u){
                temp=head,head=(dir+3)%6,dir=temp;
            }
            if(s[0]==d){
                temp=dir,dir=(head+3)%6,head=temp;
            }
            sec_main(dir);
        }
        cout<<x<< <<y<< <<z<< <<dir<<endl;
    }
    return 0;
}
View Code

题不难

但是码起来真的不舒服

建议画画图

[POJ1835]宇航员<模拟>

原文:https://www.cnblogs.com/Danzel-Aria233/p/12292392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!