32nd Diary

過去の日記
today: , yesterday: , total:
2009年
12月
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

めーるあどれす:ruby -r base64 -e 'puts Base64.decode64("dGFrQG5vMzIudGs=")'


トップ «前の日記(2009-12-16 (Wednesday)) 最新 次の日記(2009-12-18 (Friday))» 編集

2009-12-17 (Thursday) [長年日記]

SRM 455 SpidersOnTheGrid

ん。200pointsの問題。割とすぐに理解できたし、vectorも豪快に使った。

// "SpidersOnTheGrid.cpp"
#include <string>
#include <vector>
#include <iostream>

using namespace std;

class SpidersOnTheGrid {
	public:
	int find(vector <string> A) {
		vector<string> cells;
		int i, j;
		int rows = A.size();
		int columns = A[0].size();
		for(i = 0; i < rows; i++) {
			string row = "";
			for(j = 0; j < columns; j++) {
				row += " "; // spider is .
			}
			cells.push_back(row);
		}

		for(i = 0; i < rows; i++) {
			for(j = 0; j < columns; j++) {
				switch(A[i][j]) {
				case 'N':
					if(0 < i) cells[i-1][j] = '.';
					break;
				case 'S':
					if(i < rows) cells[i+1][j] = '.';
					break;
				case 'E':
					if(j < columns) cells[i][j+1] = '.';
					break;
				case 'W':
					if(0 < j) cells[i][j-1] = '.';
					break;
				default:
					break;
				}
			}
		}
		// cells is result of moving
		int free = 0;
		for(i = 0; i < rows; i++) {
			for(j = 0; j < columns; j++) {
				cout << "i, j: " << cells[i][j] << endl;
				if(cells[i][j] == ' ')free++;
			}
		}
		return free;
	}
};

テストとか通った。 って、Ustreamしてたら「それダメだから、アカウント止めたわ」のメールが・・・以前、Ustreamしてる人がいたのでいいのかと思ってた。弁解なう。

途中で挙動がおかしいと思ったてたら、システムにログインできなくなってたのかー。500pointsも途中まで書いてたんだけどなー。

追記。レーティングは上がっててワロタ。

本日のツッコミ(全1件) [ツッコミを入れる]
takano32 (2009-12-21 (Monday) 19:28)

アカウントは三ヶ月フリーズするけど、そのあともとに戻してくれるって連絡がありました。ヨカッタヨカッタ。

[]
本日のPingbacks(全0件)