SRM 602 div2 250:TypoCoderDiv2 を解きました。題意: TypoCoderには2種類の Rating がある。 Brown ➡︎ 1200以上 Ciel ➡︎ 1200以下 ただし新しい参加者は Rating 500 スタート。 N回分のコンテスト参加後の Rating が与えられるので何回色が変わったかを出…
C++で素数列挙!O( N√N )編 を書きましたが、 今度はもっと高速な エラトステネスの篩(ふるい)編 *1 を書いたのでコードを残します。 #include <bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; #include <vector> std::vect</vector></bits/stdc++.h>…
以前、C++で素数判定!を書いたのですが、 今回は C++で素数列挙!O( N √N ) のコードを書いたのでメモとして残します。 #include <bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int N; vector<int> P; void prime( co</int></bits/stdc++.h>…
深さ優先探索(DFS)を勉強中で、DFSを使って解ける優しめ問題という事で、 整数の和 | Aizu Online Judge を解きました。<題意> 0 〜 9 の数字から異なる数をN個取り出して、和がSとなる組み合わせが何個あるか出力する #include <bits/stdc++.h> using namespace std; str</bits/stdc++.h>…
ICPCOOC2016 - A Rearranging a Sequence を解きました。<題意> ・N個の整数の中から、M個の整数を移動(TOPに積む)する。 ・移動する整数M個は e[ i ] で与えられる。 ・移動後の並びを出力する。 #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(in</bits/stdc++.h>…
型で事故り、マクロtemplateを修正したのでメモ。 out #define SORT(x) sort((x).begin(),(x).end(),greater<int>()) out #define SORTP(x) sort((x).begin(),(x).end(),greater<pair<int,int>>()); in #define SORTR(x) {sort(begin(x),end(x));reverse(begin(x),end(x));}</pair<int,int></int>
過去問を解きました。 ...が、問題を解いた時間 < 提出にかかった時間 となったので記録に残します。まず、任意の過去問に移動して解く問題をselectするとGreedによって提出用ファイルがローカルに勝手に生成されます↓ ※要 Java applet の option で defaul…
std::unique *1 の挙動にハマったので覚え書き📝 #include <bits/stdc++.h> using namespace std; bool check( vector<int> A ){ sort( begin( A ), end( A ) ); return unique( begin( A ), end( A ) ) == end( A ); } int main() { vector<int> vc1{ 1,1,1,2,3,3,3,1,1,1 }; vector<int> vc</int></int></int></bits/stdc++.h>…
TopCoder 始めました。TopCoder、導入が凄く大変と聞いていたのでずっと敬遠していましたが、 過去問が良いと聞いたのでついに登録してみました。アカウントは容易に取得出来たのですが、 その後、DLした Java Applet を起動するにあたり、Mac環境でのセキュ…
std::vectorに代入された要素が全て同じ値か否かをチェックするコードを、 自分の参照用に記事として残します。 std::set は重複するデータの保持を許さないコンテナ *1 なので、 重複チェックの意味合い的にも適している、( 0 )と( 3 )を使っていこうと思い…
CodeChef デビューしましたっ!(登録しただけ) まずは Life, the Universe, and Everything (beginnerのtest用問題?)を提出して色々確認。 #include <bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int main() { </bits/stdc++.h>…
No.218 経験値1.5倍 - yukicoderを解きました。 #include <bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int main() { int A, B, C; cin >> A >> B >> C; cout << ( ( A + B - 1 ) / B * 2 / 3 < ( A + C - 1 ) /</bits/stdc++.h>…
No.22 括弧の対応 - yukicoder を解きました。括弧の対応、括弧列の問題は典型的な問題らしく、stack で解くと良いと教えて頂きました。 #include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(n); i++) using namespace std; struct cww{cww(){ios::sync_with_stdio(</bits/stdc++.h>…
Problem - 122A - Codeforcesを解きました。 #include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(n); i++) using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; bool check( int N ){ string S = to_string( N ); REP( i, (int</bits/stdc++.h>…
stackに慣れる為に車両入れ替え | Aizu Online Judgeを解きました。 #include <bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int main() { int N; stack<int> st; while( cin >> N ) { if( N == 0 ){ // 0が来たら取り</int></bits/stdc++.h>…
#include <bits/stdc++.h> using namespace std; int digit( int N ) { while( N >= 10 ) { int tmp{}; while( N > 0 ) { tmp += ( N % 10 ); N /= 10; } N = tmp; } return N; } int main() { int N{}; cin >> N; cout << digit( N ) << endl; return 0; } とある問題で桁</bits/stdc++.h>…
#include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(n); i++) using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int main() { int N; cin >> N; vector<pair<int, string>> P; REP( i, N ) { string S; cin >> S; P.emplace_back( i + 1, S );</pair<int,></bits/stdc++.h>…
No.24 数当てゲーム - yukicoder を解きました。 #include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(n); i++) using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int main() { int N; cin >> N; vector<int> res( 10, 1 ); REP( </int></bits/stdc++.h>…
std::copy_backward と std::next を覚えたのでメモ。 #include <bits/stdc++.h> using namespace std; int main() { vector<int> vc{1,2,3,4,5,6,7,8,9,10}; //指定された範囲の要素を後ろからコピーする copy_backward( vc.begin(), vc.begin() + 3, vc.end() ); for( const au</int></bits/stdc++.h>…
C: 幅優先探索 - AtCoder Beginner Contest 007 | AtCoder を解きました。 #include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(n); i++) using namespace std; typedef pair<int, int> PII; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; const int INF </int,></bits/stdc++.h>…
マクロのテンプレートをローカルの普通のメモ帳で管理してたら 間違えて消してしまったので、教えてもらったGitHubのgistにUPしました。 なんて便利なんだ...。 マクロは自分で理解したもののみ、必要になった時に増やしているので、 これからは都度、gistで…
No.3 ビットすごろく - yukicoder を解きました。 #include <bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; const int INF = numeric_limits<int>::max(); int f( int N ) { int count{}; while( N > 0 ) { if( N % 2 =</int></bits/stdc++.h>…
Codeforces Round #298 A-Exam を解きました。 #include <bits/stdc++.h> #define REP2(i,x,n) for(int i=x; i<(n); i++) using namespace std; struct CWW{CWW(){ios::sync_with_stdio(false);cin.tie(0);}}cww; int main() { int N; cin >> N; if( N <= 2 ) { cout << 1 <</bits/stdc++.h>…
Problem - A - Codeforces を解きました。 ktnさんに適度な問題をいくつかpick upして頂いたのですがそのうちの1問です。 (適度な問題:私のレベルに対しての適度)Duffちゃんが必要な肉の量/day と コスト/day がN日分与えられるので、 必要な肉を買う最小コ…
#include <bits/stdc++.h> using namespace std; //再帰 - トリボナッチ int trib( int N ) { if( N == 0 || N == 1 )//基底部 { return 0; } else if( N == 2 )//基底部 { return 1; } else //再帰部 { return trib( N - 1 ) + trib( N - 2 ) + trib( N - 3 ); } } int mai</bits/stdc++.h>…
#include <bits/stdc++.h> using namespace std; //再帰 - フィボナッチ int fib( int N ) { if( N == 0 )//基底部 { return 0; } else if( N == 1 )//基底部 { return 1; } else //再帰部 { return ( fib( N - 2 ) + fib( N - 1 ) ); } } int main() { cin.tie(0); ios::sy</bits/stdc++.h>…
#include <bits/stdc++.h> using namespace std; //再帰 - 階乗 int sum( int N ) { if( N == 0 ) //基底部 { return 1; } else //再帰部 { return N * sum( N - 1 ); } } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; cout << sum( N ) << end</bits/stdc++.h>…
#include <bits/stdc++.h> using namespace std; int sum( int N ) { if( N == 0 ) //基底部 { return 0; } else //再帰部 { return sum( N - 1 ) + 1; } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; cout << sum(n) << endl; return 0; } </bits/stdc++.h>…
No.154 市バス - yukicoderを解きました。この問題、文字列の問題を探していて星★★だったし解けるかな〜?みたいな 軽い気持ちで適当に選んだのが全ての始まりでした...(序章)初めはstd::findで文字列を見つけて場合分けすればいけるのでは(?) みたいな感じ…
Problem - 208A - Codeforcesを解きました。 #include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; S = "WUB" + S + "WUB"; regex re( "(WUB)+" ); S = regex_replace( S, re, " " ); cout << S.subs</bits/stdc++.h>…