Skip to content

Instantly share code, notes, and snippets.

View Tdrj2716's full-sized avatar
🔰

Tdrj2716

🔰
View GitHub Profile
@Tdrj2716
Tdrj2716 / Setup.md
Last active September 30, 2018 11:49
Preparation for C++ programming with Visual Studio Code

目的

競プロにむけて、高速かつ快適なC++ の開発環境を構築すること。
VSCode, MinGWを使用する。

方法

  1. VSCode のインストール
  2. MinGW のインストール
  • この際、PATH(環境変数)が適用されるようにする
  • 具体的には「システムとプロパティ」の「詳細設定」からいじる  * 最新版ではvector やstring が使えない可能性があるのでdowngrade(ver 4.9.3 を使用とのこと:https://code.i-harness.com/en/q/20653e3)
@Tdrj2716
Tdrj2716 / DP_sample(cases).cpp
Created March 26, 2018 13:36
動的計画法の練習(Combination)
#include <stdio.h>
#include <algorithm>
using namespace std;
int memo[30][30];
int dp(int i, int j)
{
if(memo[i][j] != -1)
return memo[i][j];
else if(i == 0 || j == 0)
@Tdrj2716
Tdrj2716 / ruisekiwa.md
Last active September 30, 2018 12:18
素数判定と累積和のアルゴリズムの練習です。 ABC084-D(https://beta.atcoder.jp/contests/abc084/tasks/abc084_d) の解答

累積和とは

ある区間内にある条件を満たすデータの数を出すために、あらかじめ最初からの和を取っておいて後で差を求める、というもの。 n番目までの和をSnと表す時、a番目からb番目までのデータの数はSb - Sa-1と表せる。 (SnSn-1にn番目のデータの数を加えたものなので、最後は-1)

@Tdrj2716
Tdrj2716 / imos_practice.cpp
Created September 30, 2018 13:14
imos法のサンプルコード。ABC014-C(https://beta.atcoder.jp/contests/abc014/tasks/abc014_3) の解答。
#include <cstdio>
#include <algorithm>
using namespace std;
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define N 1000001
#define MAX 1 << 20
int main(){
int n, ai, bi, s[N+1];
@Tdrj2716
Tdrj2716 / bfs.cpp
Last active November 17, 2018 15:31
グラフ関連のアルゴリズム集でuf.cppはatcoderのUnionFind(https://beta.atcoder.jp/contests/atc001/tasks/unionfind_a )、bfs.cppはatcoderの幅優先探索(https://beta.atcoder.jp/contests/atc002/tasks/abc007_3 )の答え)でdfs.cppはAOJの深さ優先探索(https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_B
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
int main(){
int r, c; cin >> r >> c;
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> a, b, c;
int n, inp;
long long int ans = 0;
struct UnionFind
{
vector<int> parent;
UnionFind(int n) : parent(n) {
for(int i = 0; i < n; i++) parent[i] = i;
}
int root(int x){
return x == parent[x] ? x : (parent[x] = root(parent[x]));
}
@Tdrj2716
Tdrj2716 / factorization.cpp
Last active March 14, 2020 02:32
素数判定のサンプルコード、及び素因数分解の問題(https://onlinejudge.u-aizu.ac.jp/problems/NTL_1_A )のソースコード
#include <iostream>
using namespace std;
int main()
{
int n; cin >> n; cout << n << ":";
int i = 2;
while(n != 1)
{
if(n % i == 0)
@Tdrj2716
Tdrj2716 / mod.cpp
Last active March 14, 2020 02:49
逆元と拡張ユークリッドの互除法
// extgcd(a, b, &x, &y): a, b(a = qb + r ---(1))が与えられるとき、ax + by = 1 ---(2)となる(x, y)を求める
// (2)に(1)を代入したとき、(qb + r)x + by = 1 ⇔ b(qx + y) + rx = 1
// ここで、extgcd(b, a % b, &s, &t)、すなわち、bs + rt = 1が成り立つとき
// s = qx + y, t = x ⇔ x = t, y = s - qx = s - a/b * x
long long extgcd(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
@Tdrj2716
Tdrj2716 / funcSample.cpp
Last active March 14, 2020 03:26
最大公約数、最小公倍数、桁和といった簡単な関数群
int gcd(int a, int b) {
return b ? gcd(b, a%b) : a;
}
int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int digsum(int n) {
int res = 0;