C++競プロ学習日記(仮)

( 学習記録であり解説Blogではないです )

競プロメモ

ABC128 B - Guidebook|tuple

B - Guidebook を解きました。 sort の工夫を覚えたのでメモ 題意 個のレストランの 所在市名 と評価 が与えられる 以下の順でレストランの番号を出力する 市名が辞書順で早いものから 同じ市に複数レストランがある場合は、評価が高いものから 考察 保持し…

ABC062 A - Grouping|AtCoder

A: Grouping - AtCoder Beginner Contest 062 | AtCoder を解きました。 A 問題ですが、学びがあったのでメモ。 題意: ・1 から 12 までの整数が下記のようにグループ分けされています。 1, 3, 5, 7, 8, 10, 12 4, 6, 9, 11 2 ・整数 が与えられるので、 が…

No.476 正しくない平均|yukicoder

No.476 正しくない平均 - yukicoder を解きました。 std::accumulateの戻り値の型 にはまったのでメモ。 #include <bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int main() { int N; long long A; cin >> N >> A</bits/stdc++.h>…

C++で素数列挙!エラトステネスの篩 編

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++で素数列挙!O( N √N )編

以前、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>…

Sum of Integers|AOJ|深さ優先探索(DFS)

深さ優先探索(DFS)を勉強中で、DFSを使って解ける優しめ問題という事で、 整数の和 | Aizu Online Judge を解きました。<題意> 0 〜 9 の数字から異なる数をN個取り出して、和がSとなる組み合わせが何個あるか出力する #include <bits/stdc++.h> using namespace std; str</bits/stdc++.h>…

ICPCOOC 2016 - A Rearranging a Sequence|AOJ

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>…

std::unique|続・重複要素チェック|C++

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>…

重複要素チェック|C++

std::vectorに代入された要素が全て同じ値か否かをチェックするコードを、 自分の参照用に記事として残します。 std::set は重複するデータの保持を許さないコンテナ *1 なので、 重複チェックの意味合い的にも適している、( 0 )と( 3 )を使っていこうと思い…

No.218 経験値1.5倍|yukicoder

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>…

C++ で 桁和

#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>…

No.3 ビットすごろく|yukicoder|幅優先探索(BFS)

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>…

Round #298 A-Exam|Codeforces

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>…

Round #326 A. Duff and Meat|Codeforces

Problem - A - Codeforces を解きました。 ktnさんに適度な問題をいくつかpick upして頂いたのですがそのうちの1問です。 (適度な問題:私のレベルに対しての適度)Duffちゃんが必要な肉の量/day と コスト/day がN日分与えられるので、 必要な肉を買う最小コ…

No.154 市バス|yukicoder

No.154 市バス - yukicoderを解きました。この問題、文字列の問題を探していて星★★だったし解けるかな〜?みたいな 軽い気持ちで適当に選んだのが全ての始まりでした...(序章)初めはstd::findで文字列を見つけて場合分けすればいけるのでは(?) みたいな感じ…

Round #130 A. Dubstep|Codeforces

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>…

Round #89 A. String Task|Codeforces

Problem - A - Codeforcesを解きました。 #include <bits/stdc++.h> using namespace std; string f( string S ) { string res; for( auto&& x : S ) { //★ if( string( "oayeui" ).find( x ) != string::npos ) { continue; } res += x; } return res; } int main() { cin.</bits/stdc++.h>…

#65 A. Way Too Long Words|Codeforces

Codeforces Round #65 Problem - A - Codeforcesを解きました。 #include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(n); i++) #define REP2(i,x,n) for(int i=x; i<(n); i++) using namespace std; int main () { cin.tie(0); ios::sync_with_stdio(false); int N;</bits/stdc++.h>…

Old Bridges|AOJ

Old Bridges | Aizu Online Judgeを解きました。 #include <bits/stdc++.h> #define LL long long #define ULL unsigned long long #define REP(i,n) for(int i=0; i<(n); i++) #define REP2(i,x,n) for(int i=x; i<(n); i++) using namespace std; int main (){ cin.tie(0)</bits/stdc++.h>…

No.163 cAPSlOCK|yukicoder

No.163 cAPSlOCK - yukicoder を解きました。 #include <bits/stdc++.h> using namespace std; int main (){ string C; cin >> C; string S; for( char x : C ){ S += ( islower(x) == 0 ? tolower(x) : toupper(x) ); } cout << S << endl; return 0; } 似ているけれど役割</bits/stdc++.h>…

No.289 数字を全て足そう|yukicoder

No.289 数字を全て足そう - yukicoder を解きました。 私の提出は見苦しいので省略。この問題は string で受け取った アルファベット + 整数 の文字列の中から 整数部分を取り出して総和を取る問題です。 string →int の変換は std::stoi() しか使った事がな…

ABC037-B 編集|AtCoder|std::fill()

B: 編集 - AtCoder Beginner Contest 037 | AtCoder を解きました。 コンテストの日に提出したコードは自分でも謎すぎて説明出来ないので割愛。 提出し直したものを...↓ #include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false</bits/stdc++.h>…

ABC037-A 饅頭|AtCoder

A: 饅頭 - AtCoder Beginner Contest 037 | AtCoder を解きました! #include <bits/stdc++.h> using namespace std; int main(){ cin.tie( 0 ); ios::sync_with_stdio( false ); int a,b,c; cin >> a >> b >> c; int res1 = c/a; int res2 = c/b; cout << max(res1,res2) <</bits/stdc++.h>…

Aizu PR|AOJ

会津PR | Aizu Online Judge を解きました。コードは置いといて、getline(cin,str)したら出力時の謎の改行に悩みました。 getline()時に改行コードを読み込んでしまっているらしかったので cinした後にcin.ignore();を書き加え改行コード読み飛ばしをしまし…

ICPC Score Totalizer Software|AOJ

ICPC Score Totalizer Software | Aizu Online Judge を解きました。 #include <bits/stdc++.h> using namespace std; int main(){ cin.tie( 0 ); ios::sync_with_stdio( false ); while(true){ int n; cin >> n; if(n == 0){ break; } int MAX = INT_MIN ,MIN = INT_MAX; v</bits/stdc++.h>…

ARC052-A 何期生?|AtCoder

A: 何期生? - AtCoder Regular Contest 052 | AtCoder を解きました。 私のコードは謎解法なのでどうでも良いです。 新しく覚えた関数をメモります! #include <bits/stdc++.h> using namespace std; int main(){ char S; cin >> S; if( isdigit( S ) ){ //数字判定 cout <</bits/stdc++.h>…

ARC050-A 大文字と小文字|AtCoder

A: 大文字と小文字 - AtCoder Regular Contest 050 | AtCoder を解きました。 #include <bits/stdc++.h> using namespace std; int main(){ string C,c; cin >> C >> c; transform(C.begin(), C.end(), C.begin(), ::tolower); cout << ( C == c ? "Yes" : "No" ) << endl; </bits/stdc++.h>…

minmax(), minmax_element()

No.292 芸名 - yukicoder を解いた時に学んだことメモ。 参考:とーらすさんの提出 #include <bits/stdc++.h> using namespace std; int main(){ int i, j; cin >> i >> j; auto temp = minmax(i, j); cout << temp.first << endl; //min値 cout << temp.second << endl; //</bits/stdc++.h>…

複素数

複素数を扱うライブラリヘッダ #include <complex>cpprefjp.github.io</complex>

doubleの比較について

先日、C: 浮気調査 - AtCoder Beginner Contest 010 | AtCoder を 解いた時に教えて貰った事をメモ。double同士の比較はEPSを足して行う。const double EPS = 0.000000000000001; const double EPS = 1e-10;if( x*x > y*y + EPS){}有限桁での浮動小数点の丸…