Skip to content

Instantly share code, notes, and snippets.

View Tdrj2716's full-sized avatar
🔰

Tdrj2716

🔰
View GitHub Profile
@Tdrj2716
Tdrj2716 / demo_proce55ing.pde
Created November 1, 2020 11:01
数行のProcessingのコードからどんなことができるかを紹介するためのサンプルコード
void setup(){
size(400, 300);
}
void draw(){
background(0);
fill(255);
ellipse(mouseX, mouseY, 10, 10);
}
@Tdrj2716
Tdrj2716 / graph.tex
Last active April 25, 2020 11:04
TeXのサンプル
\begin{tikzpicture}
\draw[->,>=stealth,thick] (-2,0)--(3,0)node[above]{$x$}; %x軸
\draw[->,>=stealth,thick] (0,-1)--(0,3)node[right]{$y$}; %y軸
\draw (0,0)node[below right]{O}; %原点
\draw[domain=-1.5:1.5] plot(\x,\x+1)node[below right]{$y=x+1$};
\draw (-1,0)node[below]{-1};
\draw (0,1)node[above left]{1};
\end{tikzpicture}
@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;
@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 / 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)
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]));
}
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> a, b, c;
int n, inp;
long long int ans = 0;
@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;
@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 / 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)