• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>


            May the force be with you!
            posts - 52,  comments - 33,  trackbacks - 0
            一次AC了這個模擬題,本來是想用面向對象的思想來寫,不過最后寫成了這個樣子。。。
                                        simbaforrest
                                        2007/12/27
            #include <iostream>
            #include 
            <stdlib.h>
            #include 
            <string.h>
            using namespace std;

            class map
            {
                
            public:
                    
            int WE;
                    
            int NS;
                    
            int grid[110][110];
                    map() {};
                    
            void init(int we, int ns)
                    {
                        WE 
            = we;
                        NS 
            = ns;
                        memset(grid,
            0,sizeof(grid));
                    };
                    inline 
            void setR(int we, int ns, int rid)
                    {grid[ns][we]
            =rid;}
                    
            void show()
                    {
                        printf(
            "map:WE=%d,NS=%d\n",WE,NS);
                        
            for(int i=NS; i>0; i--)
                        {
                            
            for(int j=1; j<=WE; j++)
                                printf(
            "%d",grid[i][j]);
                            printf(
            "\n");
                        }
                    }
                    
            void report(int rbt=-1int crash=-8)
                    {
                        
            if(rbt == -1)
                            printf(
            "OK\n");
                        
            else if(crash == -1)
                            printf(
            "Robot %d crashes into the wall\n",rbt);
                        
            else
                            printf(
            "Robot %d crashes into robot %d\n",rbt,crash);
                    };
            //        friend class robot;
            };
            map Map;

            class robot
            {
                
            public:
                    
            //static int totalnum;
                    int id;
                    
            int ns,we;
                    
            int face;
                    
            int crash;
                    robot() {};
            //        friend class command;
                    void init(int rid,int WE, int NS, char F)
                    {
                        id 
            = rid;
                        ns 
            = NS;
                        we 
            = WE;
                        Map.setR(we,ns,id);
                        crash 
            = 0;
                        
            switch(F)
                        {
                            
            case 'N':face = 0;return;
                            
            case 'S':face = 2;return;
                            
            case 'W':face = 3;return;
                            
            case 'E':face = 1;return;
                        }
                    };
                    
                    inline 
            void turnL(){face = ((face-1)+4)%4;};
                    inline 
            void turnR(){face = (face+1)%4;};
                    
            void Move()
                    {
                        Map.grid[ns][we] 
            = 0;
                        
            switch(face)
                        {
                            
            case 0:
                                ns
            ++;break;
                            
            case 1:
                                we
            ++;break;
                            
            case 2:
                                ns
            --;break;
                            
            case 3:
                                we
            --;break;
                        }
                        iscrash();
                        
            if(crash==0)
                            Map.grid[ns][we] 
            = id;
                    };
                    inline 
            void iscrash()
                    {
                        
            if(ns<=0 || ns>Map.NS || we<=0 || we>Map.WE)
                        {
                            crash 
            = -1;//crash the wall
                            return;
                        }
                        
            int idtmp = Map.grid[ns][we];
                        
            if( idtmp!=0 )
                        {
                            crash 
            = idtmp;//crash the idtmp robot
                        }
                    };
            };
            const int maxn = 101;
            robot R[
            101];

            class command
            {
                
            public:
                    
            //static int totalnum;
                    int robotid;
                    
            char action;
                    
            int repeat;
                    command() {};
                    
            void init(int id, char act, int rep)
                    {
                        robotid 
            = id;
                        action 
            = act;
                        repeat 
            = rep;
                    };
                    bool doaction()
                    {
                        
            switch(action)
                        {
                            
            case 'L':
                                
            while(repeat--)
                                {R[robotid].turnL();}
            return 1;
                            
            case 'R':
                                
            while(repeat--)
                                {R[robotid].turnR();}
            return 1;
                            
            case 'F':
                                
            while(repeat--)
                                {
                                    R[robotid].Move();
                                    
            int tmp = R[robotid].crash;
                                    
            if(tmp!=0)
                                    {
                                        
            //Map.show();
                                        Map.report(robotid,tmp);
            //                            printf("(%d,%d)\n",R[robotid].ns,R[robotid].we);
                                        return 0;
                                    }
                                }
                                
            return 1;
                        }
                    };
            };
            command C[
            101];
            int robotnum,commandnum;

            void init()
            {
                
            int A,B;
                scanf(
            "%d%d",&A,&B);
                Map.init(A,B);
            //    Map.show();
                int n,m;
                scanf(
            "%d%d",&n,&m);
                robotnum 
            = n;
                commandnum 
            = m;
                
            for(int i=1; i<=n; i++)
                {
                    
            int we,ns;
                    
            char F[5];
                    scanf(
            "%d%d%s",&we,&ns,F);
                    R[i].init(i,we,ns,F[
            0]);
                }
                
            for(int i=1; i<=m; i++)
                {
                    
            int rid,rep;
                    
            char act[5];
                    scanf(
            "%d%s%d",&rid,act,&rep);
                    C[i].init(rid,act[
            0],rep);
                }
            //    Map.show();
            }

            void begin()
            {
                
            int m = commandnum;
                
            for(int i=1; i<=m; i++)
                {
                    
            //cout<<i<<":\n";
                    if(!C[i].doaction())
                        
            return;
                    
            //Map.show();
                }
                Map.report();
            }

            int main()
            {
                
            int K;
                scanf(
            "%d",&K);
                
            while(K--)
                {
                    init();
                    begin();
                }
                
            return 0;
            }



            嗯,下面就是我的代碼了,很久以前寫的了。
            思想比較簡單,就不寫了,不過當時wa了一次:
                                                             ————by littlekid
              1 Source Code
              2 Problem: 2632        User: LittleKid
              3 Memory: 216K        Time: 0MS
              4 Language: G++        Result: Accepted
              5 
              6 
              7 # include <stdio.h>
              8 # include <string.h>
              9 
             10 # define N 111
             11 
             12 typedef struct _robot{
             13     int x,y;
             14     int dir;
             15 };
             16 
             17 int a,b;
             18 int m,n;
             19 _robot robot[N];
             20 int map[N][N];
             21 bool OK;
             22 
             23 void initialize(){
             24     for (int i = 0; i < N; i ++){
             25         map[i][0= 0;
             26         map[0][i] = 0;
             27     }
             28 }
             29 
             30 void init(){
             31     scanf("%d %d",&a,&b);
             32     for (int i = 1; i <= a; i ++){
             33         for (int j = 1; j <= b; j ++){
             34             map[i][j] = -1;
             35         }
             36         map[i][b+1= 0;
             37     }
             38     for (int i = 0; i <= b; i ++){
             39         map[a+1][i] = 0;
             40     }
             41 
             42     scanf("%d %d",&n,&m);
             43     int x,y;
             44     char d;
             45     for (int i = 1; i <= n; i ++){
             46         scanf("%d %d %c",&x,&y,&d);
             47         if (map[x][y] == 0) printf("Eroor\n");
             48         map[x][y] = i;
             49         robot[i].x = x; robot[i].y = y;
             50         switch (d){
             51             case 'N':robot[i].dir = 3;
             52                 break;
             53             case 'E':robot[i].dir = 2;
             54                 break;
             55             case 'S':robot[i].dir = 1;
             56                 break;
             57             case 'W':robot[i].dir = 0;
             58                 break;
             59             default: printf("ERROR\n");
             60         }
             61     }
             62     OK = true;
             63 }
             64 
             65 void L(int no, int re){
             66     robot[no].dir = (robot[no].dir + re) % 4;
             67     robot[no].dir += 4;
             68     robot[no].dir %= 4;
             69 }
             70 
             71 void isOK(int no){
             72   //  printf("  %d %d %d %d\n",no,robot[no].x,robot[no].y,robot[no].dir);
             73     int x = robot[no].x;
             74     int y = robot[no].y;
             75     if (map[x][y] >= 0){
             76         OK = false;
             77         if (map[x][y] == 0){
             78             printf("Robot %d crashes into the wall\n",no);
             79         }
             80         else {
             81             printf("Robot %d crashes into robot %d\n",no,map[x][y]);
             82         }
             83         return ;
             84     }
             85     map[x][y] = no;
             86 }
             87 
             88 void Forward(int no){
             89     map[robot[no].x][robot[no].y] = -1;
             90 
             91     switch (robot[no].dir){
             92         case 0: robot[no].x -= 1;
             93             break;
             94         case 1: robot[no].y -= 1;
             95             break;
             96         case 2: robot[no].x += 1;
             97             break;
             98         case 3: robot[no].y += 1;
             99             break;
            100         }
            101     isOK(no);
            102 }
            103 
            104 void F(int no, int re){
            105     while (OK && re--){
            106         Forward(no);
            107     }
            108 }
            109 
            110 void simulation(){
            111     int no,re;
            112     char action;
            113     for (int i = 0; i < m; i ++){
            114         scanf("%d %c %d",&no,&action,&re);
            115         if (OK){
            116             switch (action){
            117                 case 'L': L(no,re);
            118                 break;
            119                 case 'R': L(no,-re);
            120                 break;
            121                 case 'F': F(no,re);
            122                 break;
            123                 default: printf("ERROR!\n");
            124             }
            125         }
            126     }
            127     if (OK) printf("OK\n");
            128 }
            129 
            130 int main(){
            131     int T;
            132     initialize();
            133     scanf("%d",&T);
            134     while (T--){
            135         init();
            136         simulation();
            137     }
            138     return 0;
            139 }




            posted on 2007-12-27 15:21 R2 閱讀(889) 評論(0)  編輯 收藏 引用 所屬分類: Problem Solving
            你是第 free hit counter 位訪客




            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(4)

            隨筆分類(54)

            隨筆檔案(52)

            文章檔案(1)

            ACM/ICPC

            技術綜合

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 63330
            • 排名 - 355

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲精品tv久久久久久久久| 青青草国产精品久久久久| a级毛片无码兔费真人久久| 久久久久久九九99精品| 国内精品九九久久久精品| 日韩人妻无码一区二区三区久久| 亚洲欧美精品一区久久中文字幕 | 亚洲国产日韩综合久久精品| 人人狠狠综合久久亚洲| 四虎国产精品免费久久| 综合久久精品色| 色婷婷综合久久久中文字幕| 久久亚洲精品人成综合网| 99久久婷婷国产综合亚洲| 久久国产精品偷99| 久久久久无码精品| 日本WV一本一道久久香蕉| 色欲久久久天天天综合网精品| 久久久久人妻精品一区二区三区| 婷婷久久香蕉五月综合加勒比| 久久久无码精品亚洲日韩按摩 | 国产成人久久精品一区二区三区| 久久久精品人妻一区二区三区蜜桃| 久久99国产综合精品| 91精品日韩人妻无码久久不卡 | 99久久精品费精品国产| 亚洲欧美久久久久9999| 精品国际久久久久999波多野| 国产精品免费久久| 久久精品人人做人人爽电影 | 精品综合久久久久久88小说| 国产精品久久久久久五月尺| 久久超乳爆乳中文字幕| 久久国产精品视频| 国产精品美女久久久久久2018| 久久久国产精华液| 国产精品久久影院| 国产综合久久久久| 亚洲国产日韩欧美久久| 精品久久久久久久| 国内精品久久久久影院薰衣草|