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

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

関数

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

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

vector<pair<type, type>>の要素削除の仕方

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

std::copy_backward|std::next

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

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

再帰④|トリボナッチ数列

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

再帰と分割統治法|アルゴリズムとデータ構造

アルゴリズムとデータ構造 第6章−1「再帰と分割統治法」で階乗コードを書きました。 #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 names</bits/stdc++.h>…

stackクラス

#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; cin >> n; stack<int> st; int a; REP(i,n){ cin >> a; st.push(a);//</int></bits/stdc++.h>…

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

Aizu PR|AOJ

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

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>

CODE FESTIVAL 2015 あさぷろEasy A - ヘイホー君と加算

kouさんに無言でURLだけリプライされたので解いたです(多分解けの意code-festival-2015-morning-easy.contest.atcoder.jp #include<iostream> #include<cmath> using namespace std; int main(){ int n; cin >> n; int x = sqrt(n);//平方根 if(x*x==n){//等しい場合 cout << </cmath></iostream>…

C++でFizz Buzz

Blogを始めた時に何を書いたら良いのか解らず右往左往していたら、 カフカさんにFizz BuzzをC++で実装して晒してみる!って言われて、 そう言えばちゃんとしたFizz Buzz書いた事ない!って思って書いてみました。 #include<iostream> #include <string> using namespace std; i</string></iostream>…