0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

競プロ日記#25/03/17

Posted at

アルゴ式-マインスイーパー

  • 上下左右で斜めは考えなくてよいのでx,y方向に対しての差分配列を用意するのが良いらしい
// 差分を表す配列
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
  • これに対して以下の様に上下左右のチェックをかける
// マス (x, y) の上下左右に隣接する 4 マスを調べる
for(int d = 0; d < 4; ++d) {
    int nx = x + dx[d], ny = y + dy[d];
    // マス (nx, ny) が盤面内にあるならば、board[nx][ny] を答えに加える
    if(0 <= nx && nx < H && 0 <= ny && ny < W) {
        ans += board[nx][ny];
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?