Happy Coding

This blog is for my memorandum about programming and English.

Happy Coding

This blog is for my memorandum

グラフ理論

AtCoder Beginner Contest 010 D - 浮気予防

problem D: 浮気予防 - AtCoder Beginner Contest 010 | AtCoder how to solve This problem can be reduced to the maximum matching problems. This means that Ford-Fulkerson is among the good way to solve this problem.We have to take care that th…

Network Flow - Maximum Flow

problem Maximum Flow | Aizu Online Judge code #include <iostream> #include <vector> #define INF (1<<15) using namespace std; struct edge{ int to; int cap; int rev_id; }; class FordFulkerson { private: vector<vector<edge> > adj; int v; int e; vector<bool> visited; public: Ford</bool></vector<edge></vector></iostream>…

Build Order

problem You are given a list of projects and a list of dependencies ( which is a list of pairs of projects, where the second project is dependent on the first project). All of a project’s dependencies must be built before the project is. F…

Check Subtree

problem T1 and T2 are two very large binary trees, with T1 much bigger than T2. Create an algorithm to determine if T2 is a subtree of T1. A tree T2 is a subtree of T1 if thre exists a node n in T1 such that the subtree of n is identical t…

Atcoder Grand Contest : B Splatter Painting

problem agc012.contest.atcoder.jp how to solve The limitation of d is very small and it is key point to solve this problem. Consider that dp[v][i] which means “paint dp[v][i] among the range d distance from vertex v”. The time complexity i…

Evaluate Division

problem Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answer does not exist, return -1.0. Exa…

Trie tree

What is Trie tree? Trie tree is a data structure of handling string. - Looking up data in a trie is faster in the worst case O(m)(m is the length of a search string). - There are no collisions of different keys in a trie. - There is no nee…

First Common Ancestor

problem Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree. how to solve Starting from …

Paths with Sum

problem You are given a binary tree in which each node contains an integer value(which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The path does not need to start or end at th…

Validate BST

problem Implement a function to check if a binary tree is a binary search tree. how to solve Binary search tree means that all left nodes must be less than or equal to the current node and all right nodes must be more than or equal to the …

Check Balanced

problem Implement a function to check if a binary tree is balanced. how to solve A balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one. So I implement a function fetchHe…

AtCoder Regular Contest 044 B - 最短路問題

問題 B: 最短路問題 - AtCoder Regular Contest 044 | AtCoder note 数学の問題 最短距離がnの場所の場合の数は、最短経路がn-1である場所の数と、最短距離がnの場所の数で決まることを利用して貪欲にとく。 code

segment Treeを使用してRMQをとく。

RMQとは 数列a_0,a_1,...a_nがあるとき次の二つの処理をO(log n)で行う。 s, tが与えられたとき、a_s, a_s+1, .... , a_tの最小値を求める i, xが与えられたとき、a_iの値をxに変更する SegmentTreeとは プログラミングコンテストでのデータ構造 from Takuya…

値を固定して2点間の最短距離を求めるのを二分探索 AtCoder Beginner Contest 020 C - 壁抜け

問題 abc020.contest.atcoder.jp note 値を固定して二分探索するよくあるやつ。2点間の最短距離を求める必要があるのでダイクストラかワーシャルフロイドを使う。

動的計画法しながら幅優先探索 AtCoder Beginner Contest 021 C - 正直者の高橋くん

問題 abc021.contest.atcoder.jp あなたと高橋君は、AtCoder 王国に住んでいます。AtCoder 王国には、N 個の町と、町どうしを結ぶ M 本の道路が存在し、それらは双方向に移動可能です。 N 個の町はそれぞれ 町 1,町 2,…,町 N と呼ばれています。 また、M 個…

幅優先 AtCoder Beginner Contest 007 C - 幅優先探索

問題 abc007.contest.atcoder.jp note 普通にキューつかって幅優先するだけ

AtCoder Beginner Contest 026 C - 高橋君の給料

C - 高橋君の給料 時間制限 : 2sec / メモリ制限 : 256MB 問題文 高橋君は、社員が N 人いる会社の社長です。高橋君の会社では、以下のように給料が決まっています。 高橋君を含む社員の全員が、 1 から N までの社員番号を持っている。高橋君の社員番号はも…

AtCoder Beginner Contest 030 D へんてこ辞書

問題文 ミカミくんは怪しい英単語帳を使っています。その単語帳には N 個の単語の意味が載っており、単語 i の説明には「単語 bi と同じ意味である」とだけ書いてあります。ここで、i 番目の単語を単語 i と呼ぶことにします。 ミカミくんはまだ一つの英単語…