2016-01-26から1日間の記事一覧

No.220 世界のなんとか2

No.220 世界のなんとか2 - yukicoder 桁 DP で解く問題。3 の倍数をどうやって桁 DP に組み込むのかというと、ある桁までの mod 3 の値を状態として持っておけばよい。 計算解として 10^p - 1 - 2/3 * 9^p ってのもあるらしい。 とりあえず強引にでも DP で…

No.217 魔方陣を作ろう

No.217 魔方陣を作ろう - yukicoder やるだけ問題。でも割と楽しかった。 class MakeMagicSquare { public: typedef vector<vector<int>> Mat; void report(const Mat &mat) { int n = mat.size(); REP(i,n) { REP(j,n) { cout<<mat[i][j]; if (j < n-1) cout<<" "; } cout<<endl; } } Mat makeOddMS(int n) { Mat mat(n,vector<int>(n,0)); int i,j…</mat[i][j];></vector<int>