• <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>

            A Za, A Za, Fighting...

            堅信:勤能補拙

            PKU 1573 Robot Motion

            問題:
            http://poj.org/problem?id=1573

            思路:
            簡單題,純模擬...

            代碼:
             1 #include<stdio.h>
             2 #include<stdlib.h>
             3 #include<string.h>
             4 #define MAX_LEN 12
             5 #define is_valid(x, y) (x>=0 && x<R && y>=0 && y<C)
             6 char map[MAX_LEN][MAX_LEN];
             7 int steps[MAX_LEN][MAX_LEN];
             8 int R, C, entry;
             9 
            10 void
            11 solve()
            12 {
            13     char ch;
            14     int cx, cy, px, py;
            15     cx = px = 0;
            16     cy = py = entry-1;
            17     while(is_valid(cx, cy) && !steps[cx][cy]) {
            18         steps[cx][cy] = steps[px][py] + 1;
            19         ch = map[cx][cy];
            20         px = cx;
            21         py = cy;
            22         switch(ch) {
            23             case 'N':
            24                 cx = px-1;
            25                 cy = py;
            26                 break;
            27             case 'S':
            28                 cx = px+1;
            29                 cy = py;
            30                 break;
            31             case 'W':
            32                 cx = px;
            33                 cy = py-1;
            34                 break;
            35             case 'E':
            36                 cx = px;
            37                 cy = py+1;
            38                 break;
            39         }
            40     }
            41     if(!is_valid(cx, cy))
            42         printf("%d step(s) to exit\n", steps[px][py]);
            43     else if(steps[cx][cy])
            44         printf("%d step(s) before a loop of %d step(s)\n", steps[cx][cy]-1, steps[px][py]-steps[cx][cy]+1);
            45 }
            46 
            47 int
            48 main(int argc, char **argv)
            49 {
            50     int i;
            51     while(scanf("%d %d %d"&R, &C, &entry)!=EOF && R) {
            52         for(i=0; i<R; i++)
            53             scanf("%s", map[i]);
            54         memset(steps, 0sizeof(steps));
            55         solve();
            56     }
            57 }

            posted on 2010-10-17 11:12 simplyzhao 閱讀(139) 評論(0)  編輯 收藏 引用 所屬分類: G_其他

            導(dǎo)航

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产亚洲精品| 久久久亚洲欧洲日产国码是AV| 婷婷久久久亚洲欧洲日产国码AV | 久久人人爽人人人人片av| 狠狠综合久久AV一区二区三区| 久久天堂AV综合合色蜜桃网| 久久99精品国产99久久| 欧美麻豆久久久久久中文| 久久久久久亚洲精品成人| 久久精品中文字幕有码| 久久人人爽人人爽人人AV东京热 | 久久精品国产亚洲AV不卡| 亚洲中文字幕久久精品无码喷水| 久久精品国产69国产精品亚洲| 四虎影视久久久免费| 久久国产精品成人免费| 伊人久久大香线蕉av一区| 精品久久综合1区2区3区激情| 久久精品无码专区免费东京热| 久久久久亚洲?V成人无码| 人人狠狠综合久久亚洲88| 99蜜桃臀久久久欧美精品网站| 免费一级做a爰片久久毛片潮| 久久被窝电影亚洲爽爽爽| 精品永久久福利一区二区| 国内精品伊人久久久久777| 日韩十八禁一区二区久久| 国产成人无码精品久久久久免费 | 国产亚洲精品久久久久秋霞 | 国产精品99久久久久久董美香| AV无码久久久久不卡蜜桃| 亚洲AV无码久久| 亚洲午夜久久久久妓女影院 | 久久亚洲高清观看| 九九久久99综合一区二区| 久久国产高潮流白浆免费观看| 国产亚洲色婷婷久久99精品| 国产综合久久久久久鬼色| 久久精品国内一区二区三区| 日韩精品久久久久久| 国产国产成人久久精品|