Hatena::Grouptopcoder

TopCoderの問題を解く

解いた問題の一覧表

2009-05-11

BrickByBrick

| 20:58

問題文

479.40->1045.11 / 1100

ブロック崩しをシミュレート。実装力が問われる問題。

class BrickByBrick {
public:
    int timeToClear(vector <string> map) {
        int r = map.size();
        int c = map[0].size();
        vector<string> m(r+2, string(c+2,'#'));
        int remain = 0;
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                m[i+1][j+1] = map[i][j];
                if (map[i][j] == 'B')
                    remain++;
            }
        }

        int counter = 0;
        int idle = 0;
        int x=1, y=1, dx=1, dy=1;
        while (remain > 0 && idle < 514) {
            if (m[y][x+dx] == '.') {
                x += dx;
            } else if (m[y][x+dx] == 'B') {
                remain--, m[y][x+dx]='.', dx*=-1, idle=0;
            } else {
                dx *= -1;
            }
            counter++;
            if (remain == 0) break;

            if (m[y+dy][x] == '.') {
                y += dy;
            } else if (m[y+dy][x] == 'B') {
                remain--, m[y+dy][x]='.', dy*=-1, idle=0;
            } else {
                dy *= -1;
            }
            counter++;
            idle++;
        }

        return (remain > 0) ? -1 : counter;
    }
};

MissyMissy2011/07/22 16:09Now I know who the brainy one is, I'll keep looknig for your posts.

zrwuybrcsgozrwuybrcsgo2011/07/23 22:08xDBJGa , [url=http://ngbsklytunqc.com/]ngbsklytunqc[/url], [link=http://olpwwtwjhupr.com/]olpwwtwjhupr[/link], http://vfyjnrgeopbs.com/

qbqmjjqbqmjj2011/07/24 21:58F1VCcA <a href="http://iyopswirddsc.com/">iyopswirddsc</a>