青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 3,  comments - 1,  trackbacks - 0
這題沒把我弄瘋了.一個小時寫完,改了2個小時...題目給的數據太弱了,需要自己寫一些數據來驗證...在這里給大家提供些數據

題目
Maze
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 1205 Accepted: 399

Description

Acm, a treasure-explorer, is exploring again. This time he is in a special maze, in which there are some doors (at most 5 doors, represented by 'A', 'B', 'C', 'D', 'E' respectively). In order to find the treasure, Acm may need to open doors. However, to open a door he needs to find all the door's keys (at least one) in the maze first. For example, if there are 3 keys of Door A, to open the door he should find all the 3 keys first (that's three 'a's which denote the keys of 'A' in the maze). Now make a program to tell Acm whether he can find the treasure or not. Notice that Acm can only go up, down, left and right in the maze.

Input

The input consists of multiple test cases. The first line of each test case contains two integers M and N (1 < N, M < 20), which denote the size of the maze. The next M lines give the maze layout, with each line containing N characters. A character is one of the following: 'X' (a block of wall, which the explorer cannot enter), '.' (an empty block), 'S' (the start point of Acm), 'G' (the position of treasure), 'A', 'B', 'C', 'D', 'E' (the doors), 'a', 'b', 'c', 'd', 'e' (the keys of the doors). The input is terminated with two 0's. This test case should not be processed.

Output

For each test case, in one line output "YES" if Acm can find the treasure, or "NO" otherwise.

Sample Input

4 4
S.X.
a.X.
..XG
....
3 4
S.Xa
.aXB
b.AG
0 0

Sample Output

YES
NO
 
數據:
5 5
S....
XXAXa
GX..X
.X...
.....

20 20
S..................a
aXXXXXXXXXXAXXXXXXX.
.X........bb......X.
.XbXXXXXXXXXXXXXX.X.
.X.X.....c......X.X.
aXbX.XXXXXXXXXX.X.X.
.X.X.X........X.X.X.
.X.X.X.XDXXXX.X.X.X.
.X.X.X.X..XXX.X.X.X.
.X.X.X.X.XG.X.X.X.X.
.X.XcX.X.XXEX.CeX.X.
.X.X.X.X.e..X.X.X.X.
.X.X.X.XXXXXX.X.X.X.
.X.X.X........X.X.X.
.X.X.XXXXXXXXXX.X.X.
.X.X..c.........X.X.
.X.XXXXXXXBXXXXXX.X.
.X........b.......X.
.XXXXXXXXXXXXXXXXXX.
.d..e...a........a..
主要思想,先找鑰匙..搜索一遍,得到能找到的鑰匙,然后開門.把能開的門都打開..打開門之后再找鑰匙,然后在開門.
直到找到G..
 
代碼如下:

Source Code

Problem: 2157 User: luoguangyao
Memory: 276K Time: 0MS
Language: C++ Result: Accepted
  • Source Code
      1#include <iostream>
      2
      3using namespace std;
      4
      5int m;
      6int n;
      7char map[22][22];
      8int allkey[6= {0};
      9int key[6= {0};
     10int mark[22][22= {0};
     11int mark2[22][22= {0};
     12int markkey[22][22= {0};
     13int lock = 1;
     14int kk = 0;
     15
     16void FindKey(int x,int y)
     17{
     18    if ((map[x][y] >= 'a'&& map[x][y] <= 'e')
     19            && markkey[x][y] != 1)
     20    {
     21        key[map[x][y] - 'a']++;
     22
     23        markkey[x][y] = 1;
     24    }

     25
     26    mark2[x][y] = 1;
     27
     28    if (mark2[x + 1][y] != 1 && x + 1 < m && map[x + 1][y] != 'X' && map[x + 1][y] != 'A' && map[x + 1][y] != 'B' 
     29        && map[x + 1][y] != 'C' && map[x + 1][y] != 'D' && map[x + 1][y] != 'E')
     30    {
     31        FindKey(x + 1 , y);
     32    }

     33
     34    if (mark2[x - 1][y] != 1 && x - 1 >= 0 && map[x - 1][y] != 'X' && map[x - 1][y] != 'A' && map[x - 1][y] != 'B'
     35        && map[x - 1][y] != 'C' && map[x - 1][y] != 'D' && map[x - 1][y] != 'E')
     36    {
     37        FindKey(x - 1 , y);
     38    }

     39
     40    if (mark2[x][y + 1!= 1 && y + 1 < n && map[x][y + 1!= 'X'  && map[x][y + 1!= 'A' && map[x][y + 1!= 'B'
     41        && map[x][y + 1!= 'C' && map[x][y + 1!= 'D' && map[x][y + 1!= 'E' )
     42    {
     43        FindKey(x , y + 1);
     44    }

     45
     46    if (mark2[x][y - 1!= 1 && y - 1 >= 0 && map[x][y - 1!= 'X'  && map[x][y - 1!= 'A' && map[x][y - 1!= 'B' 
     47        && map[x][y - 1!= 'C' && map[x][y - 1!= 'D' && map[x][y - 1!= 'E')
     48    {
     49        FindKey(x , y - 1);
     50    }

     51}

     52
     53void Findroute(int x,int y)
     54{
     55    if (map[x][y] == 'G')
     56    {
     57        lock = 0;
     58    }

     59
     60    FindKey(x , y);
     61
     62    mark[x][y] = 1;
     63
     64    if (mark[x + 1][y] != 1 && x + 1 < m && map[x + 1][y] != 'X')
     65    {
     66        if (map[x + 1][y] >= 'A' && map[x + 1][y] <= 'E')
     67        {
     68            if (key[map[x + 1][y] - 'A'!= 0 && allkey[map[x + 1][y] - 'A'== key[map[x + 1][y] - 'A'])
     69            {
     70                Findroute(x + 1 , y);
     71            }

     72        }

     73        else
     74        {
     75            Findroute(x + 1 , y);
     76        }

     77    }

     78
     79    if (mark[x - 1][y] != 1 && x - 1 >= 0 && map[x - 1][y] != 'X')
     80    {
     81        if (map[x - 1][y] >= 'A' && map[x - 1][y] <= 'E')
     82        {
     83            if (key[map[x - 1][y] - 'A'!= 0 && key[map[x - 1][y] - 'A'== allkey[map[x - 1][y] - 'A'])
     84            {
     85                Findroute(x - 1 , y);
     86            }

     87        }

     88        else
     89        {
     90            Findroute(x - 1 , y);
     91        }

     92    }

     93
     94    if (mark[x][y - 1!= 1 && y - 1 >= 0 && map[x][y - 1!= 'X')
     95    {
     96        if (map[x][y - 1>= 'A' && map[x][y - 1<= 'E')
     97        {
     98            if (key[map[x][y - 1- 'A'!= 0 && allkey[map[x][y - 1- 'A'== key[map[x][y - 1- 'A'])
     99            {
    100                Findroute(x , y - 1);
    101            }

    102        }

    103        else
    104        {
    105            Findroute(x , y - 1);
    106        }

    107    }

    108
    109    if (mark[x][y + 1!= 1 && y + 1 < n && map[x][y + 1!= 'X')
    110    {
    111        if (map[x][y + 1>= 'A' && map[x][y + 1<= 'E')
    112        {
    113            if (key[map[x][y + 1- 'A'!= 0 && allkey[map[x][y + 1- 'A'== key[map[x][y + 1- 'A'])
    114            {
    115                Findroute(x , y + 1);
    116            }

    117        }

    118        else
    119        {
    120            Findroute(x , y + 1);
    121        }

    122    }

    123
    124}

    125
    126int main()
    127{
    128    int i;
    129    int j;
    130
    131    while (cin >> m >> n)
    132    {
    133        int px = -1;
    134        int py = -1;
    135        int gx = -1;
    136        int gy = -1;
    137
    138        memset(key,0,sizeof(key));
    139        memset(allkey,0,sizeof(allkey));
    140        memset(map,'\0',sizeof(map));
    141        memset(mark,0,sizeof(mark));
    142        memset(mark2,0,sizeof(mark2));
    143        memset(markkey,0,sizeof(markkey));
    144        lock = 1;
    145
    146        if (m == 0 && n == 0)
    147        {
    148            break;
    149        }

    150
    151        for (i = 0; i < m ; ++i)
    152        {
    153            for (j = 0; j < n; ++j)
    154            {
    155                cin >> map[i][j];
    156
    157                if (map[i][j] >= 'a' && map[i][j] <= 'e')
    158                {
    159                    allkey[map[i][j] - 'a']++;
    160                }

    161
    162                if (map[i][j] == 'S')
    163                {
    164                    px = i;
    165                    py = j;
    166                }

    167
    168                if (map[i][j] == 'G')
    169                {
    170                    gx = i;
    171                    gy = j;
    172                }

    173            }

    174        }

    175
    176        if (px == -1 || py == -1 || gx == -1 || gy == -1)
    177        {
    178            cout << "NO" << endl;
    179            continue;
    180        }

    181
    182        Findroute(px,py);
    183
    184        if (lock == 1)
    185        {
    186            cout << "NO" << endl;
    187        }

    188        else
    189        {
    190            cout << "YES" << endl;
    191        }

    192    }

    193
    194    return 0;
    195}

    196
posted on 2009-03-07 15:14 生活要低調 閱讀(1259) 評論(0)  編輯 收藏 引用

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用鏈接

留言簿(1)

隨筆檔案

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美视频一区在线| 久久精品视频在线播放| 欧美精品在线一区| 亚洲精品视频一区| 日韩视频在线一区| 欧美日韩精品免费观看视一区二区| 亚洲激情在线激情| 亚洲黄色成人| 欧美日韩日本国产亚洲在线| 亚洲一二三级电影| 亚洲一区二区欧美日韩| 国产专区精品视频| 欧美77777| 欧美日韩a区| 午夜亚洲性色福利视频| 欧美怡红院视频| 亚洲欧洲在线免费| 一本大道久久a久久精二百| 国产色综合久久| 亚洲第一区在线| 国产精品ⅴa在线观看h| 久久青草欧美一区二区三区| 欧美国产精品va在线观看| 亚洲欧美日韩在线综合| 久久精品视频在线看| 99视频一区| 欧美一区二区三区视频| 99这里只有久久精品视频| 亚洲欧美日韩在线一区| 亚洲理论电影网| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 日韩一区二区精品葵司在线| 在线中文字幕一区| 黄色日韩网站| 亚洲社区在线观看| 91久久精品日日躁夜夜躁国产| 一本一道久久综合狠狠老精东影业| 国产欧美日韩一区二区三区在线观看| 欧美黄色aa电影| 国产情侣一区| 一个色综合导航| 亚洲国产免费| 欧美一区2区三区4区公司二百| 日韩一二三区视频| 久久成人18免费观看| 亚洲午夜精品在线| 欧美韩日一区| 蜜乳av另类精品一区二区| 国产精品美女久久久浪潮软件| 亚洲国产成人91精品| 黄色精品免费| 久久aⅴ国产欧美74aaa| 亚洲欧美日韩在线高清直播| 欧美日韩精品二区| 亚洲精品123区| 91久久精品一区二区三区| 欧美专区18| 久久精品国产亚洲aⅴ| 欧美午夜剧场| 夜夜爽av福利精品导航| 99re6热只有精品免费观看 | 9人人澡人人爽人人精品| 亚洲国产一二三| 久久久亚洲人| 美女网站久久| 亚洲高清久久| 免费短视频成人日韩| 麻豆成人91精品二区三区| 国产一区二区三区免费不卡| 欧美一级日韩一级| 久久久亚洲国产天美传媒修理工| 国产精品尤物| 久久精品91| 免费久久99精品国产自在现线| 国产一区激情| 久久精品综合网| 欧美成人免费在线观看| 亚洲国产欧美在线 | 一本色道久久88亚洲综合88| 中日韩男男gay无套| 欧美丝袜第一区| 亚洲午夜国产成人av电影男同| 亚洲综合导航| 国产亚洲精品7777| 久久另类ts人妖一区二区| 免费成人性网站| 日韩亚洲精品视频| 国产精品久久久一区二区三区| 亚洲欧美激情一区二区| 久久精品一区二区三区不卡牛牛| …久久精品99久久香蕉国产| 免费日韩精品中文字幕视频在线| 最新亚洲一区| 欧美亚洲一区二区在线观看| 激情久久五月天| 欧美精品99| 亚洲欧美国产精品va在线观看| 久久精品亚洲精品| 亚洲精品在线二区| 国产精品久久久一本精品| 久久久精品动漫| 日韩一级不卡| 久热精品视频在线观看| aaa亚洲精品一二三区| 国产欧美一区二区三区在线老狼 | 亚洲欧美在线另类| 欧美a级一区| 亚洲自拍偷拍视频| 亚洲国产美女久久久久| 欧美午夜在线视频| 久久在线精品| 亚洲综合第一页| 亚洲国产婷婷综合在线精品| 欧美一区二区三区视频在线观看| 亚洲福利在线看| 国产精品一区二区三区久久久 | 久久久水蜜桃| 亚洲一区自拍| 亚洲欧洲在线视频| 久久久亚洲欧洲日产国码αv| 亚洲性夜色噜噜噜7777| 亚洲国产成人精品女人久久久| 国产精品久久激情| 牛人盗摄一区二区三区视频| 性18欧美另类| 亚洲欧美日韩高清| 99国产精品视频免费观看| 老鸭窝毛片一区二区三区| 亚洲欧美国产毛片在线| 日韩性生活视频| 91久久久久| 激情综合中文娱乐网| 国产视频久久久久久久| 国产精品乱人伦中文| 欧美精品在线免费播放| 欧美11—12娇小xxxx| 久久久久久国产精品mv| 久久本道综合色狠狠五月| 亚洲欧美日韩国产成人精品影院| 99v久久综合狠狠综合久久| 欧美激情中文字幕在线| 欧美va天堂在线| 久久综合狠狠综合久久综合88| 久久精品国产在热久久| 欧美在线亚洲| 久久精品视频99| 欧美一区二区成人6969| 亚欧成人在线| 久久性色av| 美腿丝袜亚洲色图| 免费在线成人av| 欧美韩日亚洲| 亚洲精品之草原avav久久| 亚洲激情小视频| 99精品热6080yy久久| 一本久道久久综合狠狠爱| 在线视频一区二区| 亚洲天堂av综合网| 午夜精品免费| 久久久久久伊人| 欧美激情va永久在线播放| 欧美日韩第一区| 国产精品久久久久秋霞鲁丝| 国产亚洲精品aa| 亚洲国产高清一区二区三区| 亚洲巨乳在线| 亚洲欧美日韩精品久久亚洲区 | 一区二区三区高清不卡| 亚洲手机视频| 久久精品官网| 欧美精品videossex性护士| 国产精品大全| 激情六月综合| 日韩视频第一页| 欧美亚洲系列| 欧美韩日精品| 亚洲欧美国产不卡| 欧美成人免费全部| 国产精品乱看| 亚洲日本国产| 午夜久久福利| 亚洲大片在线观看| 亚洲欧美精品suv| 米奇777在线欧美播放| 国产精品免费aⅴ片在线观看| 一区二区亚洲| 亚洲一卡久久| 欧美黄色成人网| 香蕉免费一区二区三区在线观看| 乱中年女人伦av一区二区| 国产精品毛片va一区二区三区| 在线观看亚洲精品视频| 亚洲一区国产一区| 欧美黄色aa电影| 欧美一区二区黄| 欧美日韩综合在线免费观看| 激情久久久久| 欧美一区免费| 一本在线高清不卡dvd| 免费观看日韩|