Drkcore

11 08 2008 cpp topcoder Tweet

SRM198-DIV2-500

赤と黒のチェッカーボードの赤い部分を数える

チェッカーボードの作り方がおかしいのに気づかず、テストがこける理由が分からなかった。

class RedSquare {
public:
  int countTheEmptyReds(int maxRank, int maxFile, vector <int> rank, vector <int> file) {
    int board[50][50];
    int result = 0;
    memset(board,0,sizeof(board));
    bool black;
    for(int   i=0; i<maxRank;++i) {
      if     (i == 0) {black  = true;}
      else if(board[i-1][maxFile-1]){black = true;}
      else {black = false;}
      for(int j=maxFile-1; j>=0; --j) {
    if(black){
      black = false;    
        }
        else{
          board[i][j] = 1;
          black = true;
        }
      }
    }

    for(int k=0;k<rank.size();++k) {
      int m = rank[k]-1;
      int n = file[k]-1;
      board[m][n] = 0;
    }

    for(int x = 0;x<maxRank;++x)
      for(int y = 0;y<maxFile;++y) 
result += board[x][y];

    return result;  
}
};

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021