読者です 読者をやめる 読者になる 読者になる

AOJ Volume11-1130

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1130&lang=jp

#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <algorithm>
using namespace std;

int main ()
{
    int w,h;
    int move_x[4] = {0,1,-1,0};
    int move_y[4] = {-1,0,0,1};
    while (cin >> w >> h) {
        if (w == 0) {
            break;
        }
        
        int filed_num[w][h];
        int count = 1;
        int start_x,start_y;
        
        //入力
        for (int i=0; i < h; i++) {
            for (int j=0; j < w; j++) {
                char hoge;
                cin >> hoge;
                
                if (hoge == '#') {
                    filed_num[j][i] = 2;
                }else if (hoge == '@') {
                    start_x = j;
                    start_y = i;
                    filed_num[j][i] = 1;
                }else {
                    filed_num[j][i] = 0;
                }
            }
        }
        
        //計算
        
        bool flag = true;
        while (flag) {
            flag = false;
            for (int i=0; i < h; i++) {
                for (int j= 0; j < w; j++) {
                    for (int k = 0; k < 4; k++) {
                        
                        if (k == 0 && i == 0) {
                            //上
                            continue;
                        }else if (k == 3 && i == (h - 1)) {
                            //下
                            continue;
                        }else if (k == 1 && j == (w - 1)) {
                            //右
                            continue;
                        }else if (k == 2 && j == 0) {
                            continue;
                        }
                        
                        if (filed_num[j + move_x[k]][i + move_y[k]] == 1 && filed_num[j][i] == 0) {
                            filed_num[j][i] = 1;
                            count++;
                            flag = true;
                            break;
                        }
                    }
                }
            }
        }
        
        
        cout << count << endl;
        
        
        
        
    }
    
    return 0;
}
広告を非表示にする