본문 바로가기

알고리즘16

페르마의 소정리 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Main { /* * 이항 계수 3 * https://www.acmicpc.net/problem/11401 */ public static void main(String[] args) throws IOException { //System.setIn(new FileInputStream("r.. 2018. 7. 17.
Union-Find import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Comparator; import java.util.PriorityQueue; import java.util.StringTokenizer; class Edge implements Comparable, Comparator { int s; int e; int w; Edge(int s, int .. 2018. 7. 17.
위상정렬 (Topological Sort) package boj; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class TopologicalSort { /* * BOJ 1516 게임 개발 * https://www.acmicpc.net/pr.. 2018. 7. 17.
SPFA (Shortest Path Faster Algorithm) import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; class Farm { int s; int e; int t; Farm (int s, int e, int t){ this... 2018. 7. 17.