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も途中まで書いてたんだけどなー。
追記。レーティングは上がっててワロタ。
[]
本日のPingbacks(全0件)









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