zoukankan      html  css  js  c++  java
  • [POJ1835]宇航员<模拟>

    链接: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

    题不难

    但是码起来真的不舒服

    建议画画图

  • 相关阅读:
    mysql随笔
    nodejs+websocket+egret
    mysql语法
    npm没反应的坑------windows配置nodejs
    nodejs打包模块问题
    nodejs中使用protobuf遇见的环境变量问题
    自己写的.net ORM 框架
    常用正则验证
    .NET中判断国内IP和国外IP
    位运算
  • 原文地址:https://www.cnblogs.com/Danzel-Aria233/p/12292392.html
Copyright © 2011-2022 走看看