- #include <bits/stdc++.h>
- using namespace std;
- int go[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
- char a[100][100];
- int c, r;
- bool visited[100][100];
- int BFS(int x, int y)
- {
- int co = 1;
- list<pair<int , int> > q;
- q.push_back(make_pair(x, y));
- list<int>::iterator i;
- while(!q.empty()) {
- pair<int, int> s = q.front();
- q.pop_front();
- //cout<<s.first<<" "<<s.second<<endl;
- for(int i = 0; i <4; i++){
- int dx = s.first + go[i][0];
- int dy = s.second + go[i][1];
- if(dx>=r ||dx< 0 || dy>= c|| dy<0 || visited[dx][dy] || a[dx][dy] =='#'){
- //cout<<"comes here"<<endl;
- continue;
- }
- //cout<<"comes"<<endl;
- co++;
- visited[dx][dy] = true;
- q.push_back(make_pair(dx, dy));
- }
- }
- return co;
- }
- int main()
- {
- int ts;
- cin>>ts;
- for(int p = 1; p <= ts; p++){
- memset(visited, false, sizeof(visited));
- cin>>c>>r;
- int cx, cy;
- for(int i = 0; i <r; i++){
- for(int j = 0; j <c; j++){
- cin>>a[i][j];
- if(a[i][j] == '@'){
- cx= i;
- cy = j;
- }
- }
- }
- visited[cx][cy] = true;
- //cout<<cx<<" "<<cy<<" ";
- cout<<"Case "<<p<<": "<<BFS(cx, cy)<<endl;
- }
- return 0;
- }
Thursday 27 July 2017
Lightoj 1012 Guilty prince
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...
-
Problem link: Problem Analysis: It is actually a basic Bisection problem , as we can see here we can not actually find a formula fo...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
No comments:
Post a Comment