• <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 位訪客




            <2007年12月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            常用鏈接

            留言簿(4)

            隨筆分類(54)

            隨筆檔案(52)

            文章檔案(1)

            ACM/ICPC

            技術綜合

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 63340
            • 排名 - 355

            最新評論

            閱讀排行榜

            評論排行榜

            国产成人综合久久精品尤物| 国产成人无码精品久久久性色| 一本色道久久综合亚洲精品| 久久婷婷色综合一区二区| 天天久久狠狠色综合| 韩国免费A级毛片久久| 国产亚洲精久久久久久无码| 国产亚洲精品美女久久久| 国产99精品久久| 日本福利片国产午夜久久| 大香网伊人久久综合网2020| 超级碰久久免费公开视频| 欧美精品丝袜久久久中文字幕| 久久无码精品一区二区三区| 伊人 久久 精品| 久久婷婷成人综合色综合| 青青草国产精品久久久久| 日日狠狠久久偷偷色综合96蜜桃| 性做久久久久久久久| 一本一道久久综合狠狠老| 国产精品美女久久久久网| 久久国产成人精品国产成人亚洲| 久久久久久青草大香综合精品| 热99RE久久精品这里都是精品免费| 亚洲狠狠婷婷综合久久久久| 国产精品久久永久免费| 色8激情欧美成人久久综合电| 久久精品人人做人人爽电影| 狠色狠色狠狠色综合久久| 久久国产精品免费一区二区三区| 伊人色综合久久天天网| 男女久久久国产一区二区三区| 久久免费精品一区二区| 久久青青色综合| 99久久无码一区人妻| 色妞色综合久久夜夜| 91超碰碰碰碰久久久久久综合| 亚洲国产成人乱码精品女人久久久不卡 | 久久99精品久久久久久动态图 | 亚洲精品高清国产一久久| 99久久做夜夜爱天天做精品|