Algorithm
ãªãã¸ã㪠競ããçãªãã¨ãä¹ ãã¶ãã«ããã®ã§ãhttp://kanetai.hatenablog.com/entry/20110519/1305833341ã®ä¸é¨ãå°ãæ´çã term description ç´æ°(divisor), å æ°,å å(factor) ããèªç¶æ°ãå²ãåãæ´æ°ã ç´ æ°(prime number) èªåèªèº«ã¨ï¼ä»¥å¤ã®èªç¶â¦
ãªãã¸ã㪠Arrays.sortã«ç¿ã£ã¦ãa[fromIndex, toIndex)ãã½ã¼ããããããã«ãã¦ã¿ãã ã¾ããjavaã«ã¯swap()ããªãã®ã§é©å½ã«å®è£ ãã¦ããã public static final void xxxSort(T a[], int fromIndex, int toIndex) { ... } public static final int[] swâ¦
æå°è²»ç¨æµåé¡ãç¹æ®åã ã½ã¼ã¹ç¯ç¹sãè¤æ°ã¦ããããé å¸ç¯ç¹wçµç±ã§ã·ã³ã¯ç¯ç¹ã«å°éããããã«æµããå辺ã«ã¯ã容éã¨å®éã®ããã¼ãä»éããã ç®æ¨ï¼ãããã¯ã¼ã¯ããã¼Fãæ大ã«ãã ã³ã¼ã æ®ä½ãããã¯ã¼ã¯ããå¢å ãã¹ãæ±ããç³»ã®ã¢ã«ã´ãªãºã ãâ¦
Network Flow Algorithms ããã¼ãããã¯ã¼ã¯(Flow network)/輸é網(Transportation network)ãæ±ãã¢ã«ã´ãªãºã ã åã¢ã¼ã¯ã«å®¹é(capacity)ãè¨å®ããåã¢ã¼ã¯ãããã¼(flow)ãæµããã ãããã¯ã¼ã¯ããã¼ã¢ã«ã´ãªãºã ã®é©ç¨åãã«ã¯æ¬¡ã®ãããªç©ããããâ¦
ãªãã¸ã㪠æåã°ã©ã(directed graph, digraph) å¼·é£çµ(strongly connected)ï¼ æåã°ã©ãã®ä»»æã®ï¼é ç¹u, vã«å¯¾ãã¦ãuããvã«å°éå¯è½ãã¤vããuã«å°éå¯è½ãããªãã¡ãä»»æã®ï¼é ç¹ã«åæ¹åã®éãåå¨ããã¨ãããã®æåã°ã©ãã¯å¼·é£çµã§ããã¨ããã â¦
ãªãã¸ã㪠Union-Find ãã¼ã¿ã®éåãç´ éåï¼äºãã«ãªã¼ãã¼ã©ããããªãéåï¼ã«åå²ãã¦ä¿æããç´ éåãã¼ã¿æ§é (disjoint-set data structure)ã«å¯¾ãã¦è¡ãã次ã®æä½ãUnion-Findã¢ã«ã´ãªãºã ã¨å¼ã¶ã Find: ç¹å®ã®è¦ç´ ãã©ã®éå(ã°ã«ã¼ã)ã«å±ãã¦â¦
ç«æ¹ä½ã®ã¦ã¼ãã£ãªãã£ã¼ã¯ã©ã¹ Spaghetti Source - ãããããåèãã¤ã¼ããã ã®ç¿»è¨³ã å³æç³»ã§ãx軸ã®æ£æ¹åãFRONT, z軸ã®æ£æ¹åãTOP. åå¤å¤å®ã¨å ¨å転ç¶æ ã®çæã§ã¯ï¼x 軸å¨ãã®å転㨠y 軸å¨ãã®å転ã交äºã«è¡ããªããï¼z 軸å¨ãã®å転ã 4 åç¹°â¦
()ããã®ååæ¼ç®ããã ãã®ã㤠ããããã¦ã³æ§æ解æã§è§£ãã BNFã§æ¸ã㨠::= | ::= | ::= '(' ')' | ::= '+' | '-' ::= '*' | '/' å·¦å帰ãåãé¤ã㨠::= ::= | ε ::= ::= | ε ::= '(' ')' | ::= '+' | '-' ::= '*' | '/' æ«å°¾å帰ã¯ã«ã¼ãã§æ¸ãã ::=â¦
ãªãã¸ã㪠ã°ã©ãçè«ï¼Graph theoryï¼ å¨éå¯è½(traversable) : å¤éã°ã©ãã®å ¨ã¦ã®é ç¹ãå«ã¿,å辺ãã¡ããã©ï¼åã ãç¨ããæ©éãåå¨ãã(ä¸çæ¸ããã§ããã°ã©ã)ã ãªã¤ã©ã¼ã°ã©ã(Eulerian graph) : ãªã¤ã©ã¼å°éãåå¨ããã°ã©ã æºãªã¤ã©ã¼ã°ã©ã(â¦
ãªãã¸ã㪠Fenwick tree, binray indexed tree(BIT) ãä¸ããããã¨ãã ç´¯ç©å å ç®æ´æ° ã®æä½ãã§ãããã¼ã¿æ§é ã§ã空éè¨ç®éã¯ãæ§ç¯ã«ãããè¨ç®éã¯(nåaddããã®ã§)ã å½ç¶ã ã(é »ç¹ã«)æ´æ°ãè¡ããªãã®ã§ããã°ãæ®éã«ã§ãã¼ãã«ä½ã£ãæ¹ãããâ¦
ãªãã¸ã㪠æ°åãä¸ããããã¨ããããããã¤ãã®é ãè±è½ãããæ°åãèããã ã«ããã¦ãæç«ããã¨ããæé·å¢å é¨åå(Longest Increasing Subsequence;LIS)ã¨ããã ç ãæçµè¦ç´ ã¨ããLISé·ã¨ãã㨠[tex: DP_i = \max \left \{ \begin{array}{lr} DPâ¦
ãªãã¸ã㪠ã°ã©ãçè«ï¼Graph theoryï¼ åä¸å§ç¹æçè·¯(Single-Source Shortest Path) å ¨ç¹å¯¾éæçè·¯(all-pairs shortest-path) æå°å ¨åæ¨(minimum spanning tree) å·¡åã»ã¼ã«ã¹ãã³åé¡(Traveling Salesman Problem) ã°ã©ãã¢ã«ã´ãªãºã ã§å ±éã§ä½¿ãè¦ç´ â¦
ãªãã¸ã㪠ã°ã©ãã®åºæ¬è¦ç´ ã¯ã°ã©ã(Graph) - kanetaiã®äºæ¬¡è¨æ¶è£ ç½®ã®ã»ãã«ã¾ã¨ããã è¨ç®çµæã®åä¸å§ç¹æçè·é¢ã¨ããã¯ãã¤ã³ã¿ãbuildPathã§æççµè·¯ãæ§ç¯ããã /** Results of Single-Source Shortest Path (SSSP) Algorithm */ public static câ¦
ãªãã¸ã㪠TODO: distanceLP distanceLL distanceLS ç¹éè·é¢ã ãã§ãªããããããã£ãæ¹ã便å©ãªã®ã§ä½ã£ã¨ã ç·åã¨ç¹ ã®ã¸ã®æ£å°å½±ãæ±ãã¦ããä¸ã«ããã°ã ç¡ããã°ã //instance method of Point class public final double distancePS(Line s){ Poinâ¦
æ£å°å½±(orthograph, orthogonal projection) å°å½±(projection)ãé¡æ (reflection) ä¸ç¹ããããç´ç·ã¾ãã¯å¹³é¢ä¸ã«ä¸ãããåç·ã®äº¤ç¹(åç·ã®è¶³:foot of a perpendicular)ãå³å½¢(ç¹ã®éå)ã«ã¤ãã¦ããå³å½¢ä¸ã®ãã¹ã¦ã®ç¹ã®åç·ã®è¶³ã®éåãæ£å°å½±ã¨å¼ã¶ã â¦
ãªãã¸ã㪠巡åã»ã¼ã«ã¹ãã³åé¡(TSP: Traveling Salesman Problem) æçããã«ãã³éè·¯(åé ç¹ã1åã ãå«ã(éå§ã»çµäºç¹ãé¤ã)éããæ©é(éè·¯))ãè¦ã¤ããåé¡ NPå°é£ãªãããå¤é å¼æéã§è§£ããªãã競æããã°ã©ãã³ã°ã§ã¯ããããDPã«ãã解æ³ãç¥ã£â¦
ãªãã¸ã㪠è¨ç®çµæï¼æçè·é¢ã¨ããã¯ãã¤ã³ã¿ï¼ æççµè·¯ã¯buildPath()ã§å¾©å ã /** Results of All-Pairs Shortest Path (APSP) Algorithm */ public static class APSPResult{ private int[][] dist; // dist[d]:= shortest path to d private int[][] â¦
åèãã¼ã¸ éæ¹é£ - Wikipedia http://www2u.biglobe.ne.jp/~zed/m_stitle.htm éæ¹é£(magic square) æ£æ¹å½¢ã§ç¸¦ã»æ¨ªã»æã®æ°åã®åè¨ããã¹ã¦çããæ¹é£ã ç¹ã«ã(次)ã®è¡åã®æ¹é£ã®è¦ç´ ã¨ãã¦()ãéè¤ãªã使ç¨ãããã®ãéæ¹é£ã¨å¼ã¶ãã¨ãå¤ãã ãã®å ´â¦
ãªãã¸ã㪠ãã¥ã¼ãã³æ³(Newton's method), ãã¥ã¼ãã³ã»ã©ãã½ã³æ³(Newton-Raphson method) éç·åæ¹ç¨å¼ã®å復çãªæ°å¤è§£æ³ã®ä¸ã¤ã ããå°ã詳ãã説æã¯ãã¥ã¼ãã³æ³ - Wikipediaã åæå¤ãä¸ãã¦ããåæããã¾ã§(ä¾ãã°ãå¢åãå°ãããªã()ã¾ã§)ç¹°â¦
ãªãã¸ããª å ¨åæ¨(spanning tree), æ¥µå¤§æ¨ : ã«ããã¦ã¨ãªã辺éåãããã¨ããã°ã©ããæ¨ï¼éè·¯ãæããªãã°ã©ãï¼ã§ãããªãã ãã®å ¨åæ¨ã¨å¼ã¶ã (å ¨åæ¨ãåå¨ãããã¨ã¨é£çµã§ãããã¨ã¯åå¤) æå°å ¨åæ¨(MST: Minimum Spanning Tree) : 使ããã辺ã®â¦
ãªãã¸ã㪠TODO: intersect_LS intersect_LP åèãã¼ã¸æã®æå·¥æ¿ - 2ç´ç·ã®äº¤ç¹ãæ±ãã ç´ç· å¹³é¢å¹¾ä½(plane geometory) ã使ã£ã¦ãç´ç·ã¯ã©ã¹ãä½ã£ã¦ã¿ãã(ç´ç·(line)ã¨ããã¤ã¤ããç·å(segment)ã¨ãã¦ã使ãã®ã§æ³¨æ) public static class Line{ prâ¦
ãªãã¸ã㪠next_permutation - C++ Reference Javaã«next_permutationãç¡ãã®ã§ãä½ã£ã¦ã¿ãã C++ã®std::next_permutationãããã ããé åãå ¨åæããããªãã¯ããã«æé ã½ã¼ããã¦ããã¦ãdo-whileã®whileã®ä¸ã§nextPermutationã使ããªãã¨ãããªããâ¦
ãªãã¸ã㪠ç¹(point) complexã¯ã©ã¹ãããã°ããã§ä»£ç¨ãã¦ãããã æ¼ç®åãªã¼ãã¼ãã¼ããç¡ãã¨é¢åãããã æ³ç·ãã¯ãã«ã¯è¤ç´ æ°ãèããã°ããããã import java.awt.geom.Point2D; static final double EPS = 1e-10; static boolean equal(double aâ¦
ãªãã¸ã㪠binary_search - C++ Reference lower_bound - C++ Reference upper_bound - C++ Reference â»ã»ã¼å ¨é¨æªæ¤è¨¼ 2åæ¢ç´¢(binary search) ã½ã¼ãæ¸ã®ãã¼ã¿ã«å¯¾ãã¦ã§æ¢ç´¢ãè¡ã(ã¯ãã¼ã¿æ°)ã ããã¦ãã®è¨èªã«æ¨æºã§2åæ¢ç´¢ã®é¢æ°ãç¨æããã¦ãã®â¦
ãªãã¸ã㪠åèã«ãªããããªãã¼ã¸ ï¼ï¼¡ã®å¤©æè¨ç®ãµã³ãã«é â æ¥æã¨ã¦ãªã¦ã¹æ¥ã®å¤æ éé£ç³»ç«ç楽æ¸å¸³ éå¹´(leap year) ã¦ãªã¦ã¹æ¦(Julian calendar)ã¯ãç´å å46å¹´ãå¤ä»£ãã¼ãã§æ¡ç¨ãããã4å¹´ã«1åã西æ¦å¹´ã4ã§å²ãåããå¹´ãéå¹´ã¨ãã¦ãããç¾è¡â¦
ãªãã¸ã㪠åèã«ãªããããªãã¼ã¸ å帰ã¢ã«ã´ãªãºã ã«ããã¦ã¼ã¯ãªããäºé¤æ³ æå¤§å ¬ç´æ°(GCD;Greatest Common Divisor) 2ã¤ä»¥ä¸ã®æ´æ°ã®æå¤§å ¬ç´æ°ã¯ã®æ大ã®å ¬ç´æ° Euclidã®äºé¤æ³(Euclidean algorithm, Euclid's algorithm) ã«ã¤ãã¦ããæç«ãããã¨ãâ¦
åæ°å¶éãªããããã¶ãã¯åé¡(ããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ã¸ãã㯠p58) éãã¨ä¾¡å¤ãããããã§ãããããªåã®åç©ãããã ãããã®ä¸ããéãã®ç·åããè¶ ããªãããã«é¸ãã æã®ä¾¡å¤ã®ç·åã®æ大å¤ãæ±ããã ãã ããåãåç©ãããã¤ã§ãé¸ãã§â¦
æé·å ±éé¨åååé¡(LCS; Longest Common Subsequence) äºã¤ã®å¤ã®åãä¸ãããã¦ï¼æé·ã®å ±éé¨ååãè¦ã¤ããåé¡ã é¨ååã¯é£ç¶ãã¦ããå¿ è¦ã¯ãªããï¼é åºã¯å¤æ´ãã¦ã¯ãã LCSã¯ä¸è¬çã«è¤æ°ããã Common Subsequence(PKU No.1458) äºã¤ã®æååã¨ãâ¦
01ãããã¶ãã¯åé¡(ããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ã¸ãã㯠p34) éãã¨ä¾¡å¤ãããããã§ãããããªåã®åç©ãããã ãããã®ä¸ããéãã®ç·åããè¶ ããªãããã«é¸ãã æã®ä¾¡å¤ã®ç·åã®æ大å¤ãæ±ããã å¶ç´ ã¢ã«ã´ãªãºã 1 içªç®ä»¥éã®åç©ããéãã®â¦
ãªãã¸ã㪠TODO: é£ç«ç·å½¢åå ä¸å½å°ä½å®ç mod_fact cCk mod p ... ååå¼(modular equality) äºã¤ã®æ´æ°, èªç¶æ°ã«ã¤ãã¦ã ãªãã , () ã¨æ¸ããããæ³(modulus)ã¨ãã¦åå(congruent)ã¨ããã ä¸ã®æ§è³ªãããå æ¸ä¹é¤ãçµã¿åãããååæ¼ç®ã§ã¯ãéä¸â¦