Skip to content

Instantly share code, notes, and snippets.

@ShibeHasu
ShibeHasu / PrimalDual.cpp
Created April 12, 2024 15:09
最小費用流を解きます
namespace template_algorithm {
template<typename flow_T, typename cost_T>
class primal_dual {
//辺クラス
private: class edge {
public:
int to;
flow_T cap;
cost_T cost;
int rev;
@ShibeHasu
ShibeHasu / LazySegmentTree.cpp
Created March 20, 2024 14:38
抽象化した遅延セグメント木です
#include <bits/stdc++.h>
using namespace std;
namespace template_algorithm {
template<typename T>
class lazy_segment_tree {
public:
lazy_segment_tree(vector<T> &vec, T e_, T lazy_e_, function<T(T, T)> mapping_,
function<T(T, T)> operation_, function<T(T, T)> composition_, function<T(T, int)> multiplier_)
: e(e_), lazy_e(lazy_e_), mapping(mapping_), operation(operation_), composition(composition_),
@ShibeHasu
ShibeHasu / FordFulkerson.cpp
Created March 14, 2024 14:36
フォードファルカーソン法です。(最大流を求めるアルゴリズム)
#include <bits/stdc++.h>
using namespace std;
namespace template_algorithm {
/*辺情報*/
template<typename T>
struct edge {
//rev := to(辺の終点)の隣接リストでの辺の始点へ向かう逆辺の番号
int rev;
int to;
@ShibeHasu
ShibeHasu / SegmentTree.cpp
Created March 12, 2024 14:39
抽象化したセグ木(遅延には非対応)です
#include <bits/stdc++.h>
using namespace std;
namespace template_algorithm {
template<typename T>
class segment_tree {
public:
/// @brief n_個に合わせてツリーを作り、値を単位元で埋めるコンストラクタ1
/// @param n_ 区間サイズ
/// @param e_ 単位元
@ShibeHasu
ShibeHasu / Dijkstra.cpp
Last active April 23, 2024 05:26
使い回せるようにしたダイクストラ法です。 最短距離と経路復元ができます。
namespace template_algorithm {
/// @brief ダイクストラ法(クラス)
/// @attention 求められるものは「startからの」最短経路。 求める際は0-indexedにすること。
template<typename T>
class dijkstra{
public:
/// @brief 辺クラス
class edge{
public:
int to;
@ShibeHasu
ShibeHasu / BinarySearch.cpp
Last active April 3, 2024 14:59
汎用二分探索
#include <bits/stdc++.h>
using namespace std;
namespace template_algorithm {
template<typename T>
class binary_search {
public:
//コンストラクタ
binary_search(bool is_maximize_, function<bool(T)> fn_)
: is_maximize(is_maximize_), is_ok(fn_) {};
@ShibeHasu
ShibeHasu / operator_overload.cpp
Last active February 27, 2024 16:17
自分定義のクラスの比較方法の定義
#include <bits/stdc++.h>
using namespace std;
/// @brief 辺のクラス: 比較は辺の重みでしたいとする
/// @tparam T コストなどの型
template<typename T>
class edge{
public:
T to;
T cost;
@ShibeHasu
ShibeHasu / priority_queue_change_sort.cpp
Created February 24, 2024 16:37
priority_queueの比較方法を変更する方法です
#include <bits/stdc++.h>
using namespace std;
int main() {
//比較関数だよ: lの優先順位が低い時にtrueを返すらしいよ
auto compare = [](int l, int r) { return abs(l) < abs(r); };
//「decltype(比較関数)」と「変数名(比較関数)」が増えたよ
priority_queue<int, vector<int>, decltype(compare)> pq(compare);
//今回は絶対値が大きい順にソートされて出てくるよ
@ShibeHasu
ShibeHasu / number_place_solve.cpp
Last active February 27, 2024 16:08
数独(9*9)を解きます
#include <bits/stdc++.h>
using namespace std;
/*数独ソルバー
使い方:step1
まず表に最初から埋まっている数を一行ごとに入力していきます
空いているマスは0で表します
step2
コードを実行する
*/