- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<cmath>
- #include<algorithm>
- #include<string>
- #include<stack>
- #include<queue>
- #include<map>
- #include<vector>
- using namespace std;
- #define loop(i, n) for(int i=0; i<n; i++)
- #define FOR(i, s, e) for(int i=s; i<e; i++)
- #define pb push_back
- #define mem(a, v) memset(a, v, sizeof(a))
- #define SZ size()
- #define pi acos(-1.0)
- #define INF 1<<29
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- #define ll long long
- #define mod(a) (a>0?(a):(-a))
- #define get(n) scanf("%d", &n)
- #define MAXX 505
- #define debug cout<<"ok"
- int count_row, count_column;
- char graph[MAXX][MAXX];
- int* dp[MAXX][MAXX];
- int value[MAXX][MAXX];
- bool visited[MAXX][MAXX];
- int p, q;
- void dfs(int x, int y)
- {
- if(x<0 || x == count_row || y<0 || y == count_column || visited[x][y] || graph[x][y] == '#') return;
- dp[x][y] = &value[p][q];
- visited[x][y] = true;
- if(graph[x][y] == 'C')
- {
- value[p][q]++;
- }
- dfs(x+1, y);
- dfs(x-1, y);
- dfs(x, y-1);
- dfs(x, y+1);
- return;
- }
- int main()
- {
- int kases, kaseno = 0;
- int query;
- get(kases);
- while(kases--)
- {
- mem(visited, false);
- get(count_row);
- get(count_column);
- get(query);
- loop(i, count_row)
- {
- scanf("%s", graph[i]);
- }
- printf("Case %d:\n", ++kaseno);
- loop(i, query)
- {
- get(p);
- get(q);
- p--;
- q--;
- if(graph[p][q] == '#')
- {
- printf("0\n");
- continue;
- }
- if( ! visited[p][q] )
- {
- value[p][q] = 0;
- dfs(p, q);
- }
- printf("%d\n", *(dp[p][q]));
- }
- }
- return 0;
- }
Saturday, 29 July 2017
Lightoj 1337 - The Crystal Maze
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment