LightOJ-1337 the Crystal Maze

Source: Internet
Author: User


Large output input, note with scanf,printf, otherwise it may time out


#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>//#include < map> #include <set> #include <vector> #include <queue> #include <stack> #include <string&
Gt
using namespace Std;

#define LL Long Long const int MAXN = 505;
Char MAP[MAXN][MAXN];
BOOL VIS[MAXN][MAXN];
int N, m, Q, X1[MAXN*MAXN], Y1[MAXN*MAXN], top, ans, an[maxn][maxn];

int dis[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
        void Dfs (int x, int y) {vis[x][y] = 1;
        if (map[x][y] = = ' C ') ans + +;
        X1[top] = x, Y1[top + +] = y;
                for (int i = 0; i < 4; i + +) {int xx = x + dis[i][0];
                int yy = y + dis[i][1]; if (xx >= 0 && xx < n && yy >= 0 && yy < m &&!vis[xx][yy] && map[xx][
                YY] = ' # ') {dfs (xx, yy);
}} return;
        } int main () {int T, case = 0; scanf ("%D ", &t);
                while (T--) {scanf ("%d%d%d", &n, &m, &q);
                memset (Vis, 0, sizeof (VIS));
                Memset (AN,-1, sizeof (an));
                for (int i = 0; i < n; i + +) {scanf ("%s", Map[i]);
                } int x, y;
                printf ("Case%d:\n", + + case);
                        for (int i = 0; i < q; i + +) {scanf ("%d%d", &x, &y);
                        if (an[x-1][y-1] = = 1) {top = 0, ans = 0, dfs (x-1, y-1);
                        } for (int j = 0; J < top; J + +) {An[x1[j]][y1[j]] = ans;
                } printf ("%d\n", an[x-1][y-1]);
 }
        }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.