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

posts - 74,  comments - 33,  trackbacks - 0

Problem Statement

???? According to research conducted recently, listening to classical music increases one's mental abilities, while listening to metal decreases them. Now, yet another experiment is being conducted to try to prove or disprove this statement.

In this new experiment, a mouse is placed in a rectangular maze consisting of NxM squares. Each square either contains a wall or is empty. The maze is structured in such a way that for any two empty squares, there exists exactly one path between them. A path is a sequence of pairwise distinct empty squares such that every two consecutive squares are neighboring. Two squares are considered neighboring if they share a common edge.

One of the empty squares in the maze contains a piece of cheese. The mouse's goal is to reach that square without visiting the same square twice. The mouse can only move between neighboring squares. Since the mouse has been listening to classical music for a week, he is extremely intelligent and guaranteed to achieve his goal.

As the mouse moves from his starting point to the cheese, he may encounter some squares where he must choose between several neighboring squares to continue. This happens when the mouse steps into a square which has more than one neighboring empty square, excluding the square from which he came, or when he has more than one neighboring empty square at the start. These situations are called "decisions" and the mouse will always make the right choice.

You are given a vector <string> maze representing the maze. It contains N elements, each containing M characters. Empty squares are denoted by '.', walls are denoted by uppercase 'X', the mouse's starting point is denoted by 'M', and the square containing the cheese is denoted by '*'. Return the number of decisions the mouse will make on his way to the cheese.

Definition

????
Class: MazeWanderingEasy
Method: decisions
Parameters: vector <string>
Returns: int
Method signature: int decisions(vector <string> maze)
(be sure your method is public)
????

Constraints

- maze will contain between 1 and 50 elements, inclusive.
- Each element of maze will contain between 1 and 50 characters, inclusive.
- Elements of maze will be of the same length.
- maze will contain only '.', 'X', 'M' or '*' characters.
- There will be exactly one '*' character in maze.
- There will be exactly one 'M' character in maze.
- For every pair of empty squares in the maze, there will exist exactly one path between them.

Examples

0)
????
{"*.M"}
Returns: 0
From each square, the mouse can only move to one other square, so he never has to make any decisions.
1)
????
{"*.M",
 ".X."}
Returns: 1
The mouse has to make a decision right at the start.
2)
????
{"...",
 "XMX",
 "..*"}
Returns: 2
The mouse makes decisions at both squares before reaching the cheese.
3)
????
{".X.X......X",
 ".X*.X.XXX.X",
 ".XX.X.XM...",
 "......XXXX."}
Returns: 3
4)
????
{"..........*",
 ".XXXXXXXXXX",
 "...........",
 "XXXXXXXXXX.",
 "M.........."}
Returns: 0

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
這道題是簡單的BFS由于 對C++的不熟悉導致比賽的時候 怎么寫一直猶豫不決剛才搞了搞C++終于寫出來了 原來可以這樣寫的

#include < cstdio >
#include
< vector >
#include
< queue >
#include
< string >
#include
< cstring >
#define ?MAXN?120
using ? namespace ?std;
const ? int ?dir[ 4 ][ 2 ] = { { - 1 , 0 } , { 1 , 0 } , { 0 , - 1 } , { 0 , 1 } } ;
struct ?NODE {
????
int ?x,y,sum;????
}
pt;
queue
< NODE > Q;
class ?MazeWanderingEasy {
????
public ?:
????????
int ?decisions(vector < string > ?maze) {
????????????
int ?n,m,i,j,all,res;
????????????n
= maze.size();m = maze[ 0 ].length();
????????????
while ( ! Q.empty())Q.pop();
????????????
bool ?mark[MAXN][MAXN];
????????????memset(mark,
0 , sizeof (mark));
????????????
for (i = 0 ;i < n;i ++ )
????????????????
for (j = 0 ;j < m;j ++ )
????????????????????
if (maze[i][j] == ' M ' ) {
????????????????????????pt.x
= i,pt.y = j,pt.sum = 0 ;
????????????????????????Q.push(pt);
????????????????????????
break ;
????????????????????}

????????????mark[i][j]
= true ;
????????????
while ( ! Q.empty()) {
????????????????pt
= Q.front();
????????????????
int ?x = pt.x,y = pt.y;
????????????????
if (maze[x][y] == ' * ' ) {
????????????????????res
= pt.sum;
????????????????????
break ;
????????????????}

????????????????
for (all = i = 0 ;i < 4 ;i ++ ) {
????????????????????
int ?nx = x + dir[i][ 0 ];
????????????????????
int ?ny = y + dir[i][ 1 ];
????????????????????
if (nx < n && nx >= 0 && ny < m && ny >= 0 &&! mark[nx][ny] && maze[nx][ny] == ' . ' )all ++ ;????
????????????????}

????????????????
for (all = i = 0 ;i < 4 ;i ++ ) {
????????????????????
int ?nx = x + dir[i][ 0 ];
????????????????????
int ?ny = y + dir[i][ 1 ];
????????????????????
if (nx < n && nx >= 0 && ny < m && ny >= 0 &&! mark[nx][ny] && maze[nx][ny] == ' . ' ) {
????????????????????????mark[nx][ny]
= true ;
????????????????????????pt.x
= nx,pt.y = ny,pt.sum = Q.front().sum + all - 1 ;
????????????????????}
????
????????????????}

????????????????Q.pop();
????????????}

????????????
return ?res;
????????}
????
}
;


?

posted on 2009-05-12 22:10 KNIGHT 閱讀(197) 評論(0)  編輯 收藏 引用
<2009年1月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用鏈接

留言簿(8)

隨筆檔案

文章檔案

Friends

OJ

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲日本久久| 一区二区三区导航| 久久综合久色欧美综合狠狠| 亚洲线精品一区二区三区八戒| 亚洲国产福利在线| 亚洲欧美国产另类| 欧美在线一二三| 久久偷看各类wc女厕嘘嘘偷窃| 久久精品日韩| 欧美国产极速在线| 午夜精品免费| 在线一区亚洲| 国产欧美日韩激情| 国产亚洲精品激情久久| 一区在线播放视频| 亚洲美女精品久久| 亚洲免费综合| 玖玖综合伊人| 亚洲三级观看| 亚洲自拍偷拍色片视频| 久久精品视频播放| 欧美日韩精品一区二区天天拍小说 | 国产精品v一区二区三区| 国产精品一区二区在线| 激情成人av在线| 99视频精品全国免费| 欧美一区二区三区婷婷月色| 久久影院午夜论| 中文亚洲免费| 欧美电影在线免费观看网站| 国产精品亚洲а∨天堂免在线| 亚洲激情视频网站| 久久久久高清| 亚洲国产一区二区在线| 免费亚洲电影在线观看| 在线精品国精品国产尤物884a| 亚洲乱码日产精品bd| 久久精品在线免费观看| 日韩一区二区精品| 欧美freesex8一10精品| 国产美女精品| 亚洲精品久久久久久久久久久久久| 亚洲欧美日本国产专区一区| 亚洲国产精品一区| 久久超碰97人人做人人爱| 国产精品www.| 亚洲视频精选在线| 亚洲高清自拍| 久久久久一区二区| 国产偷国产偷亚洲高清97cao| 欧美国产日本韩| 欧美亚洲免费电影| 欧美日韩一区二| 亚洲日本成人网| 免费毛片一区二区三区久久久| 一区二区三区精品视频| 欧美成人精品高清在线播放| 亚洲成人资源| 久久久另类综合| 午夜精品亚洲| 国产欧美一区二区三区久久| 亚洲一区黄色| 在线一区二区三区做爰视频网站| 欧美黄色日本| 99riav1国产精品视频| 欧美国产一区二区在线观看 | 在线欧美福利| 久久天天躁狠狠躁夜夜av| 亚洲综合视频网| 国产欧美精品在线| 欧美影院成人| 欧美一站二站| 国内精品视频一区| 免费观看日韩| 欧美va亚洲va香蕉在线| 亚洲精品影院| 99国产精品国产精品毛片| 欧美婷婷久久| 欧美在线视频免费| 久久av二区| 亚洲国产一区二区三区青草影视 | 欧美电影在线观看| 亚洲一二三四久久| 欧美一区国产二区| 在线观看视频欧美| 亚洲日本成人| 国产精品夜夜嗨| 欧美成人午夜激情| 欧美色偷偷大香| 久久久久久亚洲综合影院红桃| 久久久噜噜噜久久久| 一区二区三区不卡视频在线观看| 一二三四社区欧美黄| 国产亚洲女人久久久久毛片| 欧美国产日韩免费| 国产精品美女一区二区| 久久这里有精品15一区二区三区| 欧美激情一二三区| 久久精品一区二区三区四区| 欧美成人a视频| 久久精品国产亚洲一区二区三区| 嫩草成人www欧美| 欧美一区国产一区| 欧美激情在线观看| 久久久久久久久伊人| 欧美精品一区二区三区四区| 巨乳诱惑日韩免费av| 在线成人激情| 亚洲福利国产| 国产精品日日摸夜夜摸av| 免费看av成人| 国产精品久久久久影院色老大 | 一区二区免费在线观看| 国产一区二区日韩精品| 亚洲人午夜精品| 亚洲国产cao| 欧美在线播放| 亚洲欧美综合v| 欧美精品久久久久久久免费观看 | 午夜欧美精品久久久久久久| 欧美sm视频| 欧美国产国产综合| 精久久久久久久久久久| 午夜精品久久久久久久99水蜜桃| 99视频热这里只有精品免费| 久久久久久有精品国产| 久久久久久999| 欧美三级小说| 亚洲精品日日夜夜| 最新成人av网站| 欧美影院成年免费版| 午夜精品一区二区三区在线播放| 欧美日韩国产一级| 亚洲美女毛片| 一区二区三区欧美| 欧美人与性禽动交情品 | 国产日韩欧美制服另类| 一区二区三区精品视频在线观看| 在线一区二区三区四区五区| 欧美日产一区二区三区在线观看| 欧美激情一区二区三区在线| 在线观看视频一区二区| 久久久另类综合| 亚洲国产精品999| 亚洲免费av观看| 欧美日韩国产免费观看| 亚洲精品乱码久久久久久蜜桃麻豆 | 久久久999国产| 国户精品久久久久久久久久久不卡| 性一交一乱一区二区洋洋av| 欧美一区二区私人影院日本| 国产精品福利影院| 午夜视频一区在线观看| 久久一区二区三区国产精品| 怡红院精品视频在线观看极品| 巨乳诱惑日韩免费av| 亚洲区免费影片| 午夜精品久久久久久| 国产亚洲精品美女| 亚洲丰满在线| 亚洲一区二区欧美| 亚洲女爱视频在线| 国产日韩精品一区二区三区| 欧美在线亚洲一区| 欧美激情视频在线播放 | 久久久久亚洲综合| 亚洲高清视频一区二区| 欧美激情亚洲国产| 亚洲男人的天堂在线| 你懂的视频欧美| 在线视频精品一区| 国产精品一二一区| 裸体一区二区| 日韩一级片网址| 久久精品视频播放| 亚洲美女av电影| 国产精品影音先锋| 免费成人性网站| 亚洲一区二区在线免费观看| 久久综合给合久久狠狠色| 99ri日韩精品视频| 国产在线欧美日韩| 欧美午夜美女看片| 美女福利精品视频| 午夜精品一区二区三区四区| 亚洲品质自拍| 久久一区二区精品| 欧美一区二区精品| 亚洲免费电影在线| 一区精品久久| 国产乱肥老妇国产一区二| 欧美成人精品激情在线观看| 午夜精品久久久久久久99热浪潮 | 亚洲尤物在线视频观看| 欧美成人免费全部| 久久久国产精品一区| 午夜久久黄色| 亚洲一区在线播放| 日韩视频免费观看| 亚洲欧洲日本一区二区三区|