Drkcore

07 07 2008 cpp topcoder Tweet

SRM188-DIV2-250&500

250点は縦横の合計が同じようになるように。3列のそれぞれの合計を比較して異なる数字のとこから入れるべき値を決定。

class MagicSquare {
public:
  int missing(vector <int> square) {
    int total[3] = {0,0,0};
    for(int i = 0;i<square.size();i++) total[i%3] +=square[i];
    if(total[0] == total[1]) return total[0] - total[2] - 1;
    if(total[0] == total[2]) return total[0] - total[1] - 1;
    if(total[2] == total[1]) return total[1] - total[0] - 1;
  }
 };

500点問題は小数点以下2桁を四捨五入したパーセントから、最小の母数を求める。母数を増やしながらパーセントを求めつつ四捨五入して比較。最初の正解が最小の母数。

class Percents {
public:
  int minSamples(string percent) {
    double pc;
    if(percent == "00.00%") return 1;
    stringstream ss;
    ss << percent;
    ss >> pc;
    for(int i=2;i<=10000;i++){
       for(int j=1;j<i;j++){
    double x = round(((double) j/i) * 10000) / 100;
      if(x == pc) return i;
      }
    }
    return 0;
  }
};

そろそろ1000点問題も解いていくか。

About

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

Tag

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

Ad

© kzfm 2003-2021