原创 藍橋杯-風險度量-並查集

X星系的的防衛體系包含 n 個空間站。這 n 個空間站間有 m 條通信鏈路,構成通信網。兩個空間站間可能直接通信,也可能通過其它空間站中轉。對於兩個站點x和y (x != y), 如果能找到一個站點z,使得:當z被破壞後,x和y無法通信,

原创 素數算法

1、素數判定 給定整數n,判斷n是不是素數。 0<n<=10^9 n除了本身,所有的約數都不大根號n,算法複雜度爲O(√n)  //素數判定 bool is_prime(int n) { for(int i=2;i*i<=n;i+

原创 POJ2686 Traveling by Stagecoach 狀態壓縮DP

Description Once upon a time, there was a traveler.  He plans to travel using stagecoaches (horse wagons). His starting

原创 POJ1837 Balance 01揹包

Description Gigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other or

原创 POJ1416 Shredding Company深搜

Description 題幹     Input The input consists of several test cases, each on one line, as follows :  tl num1  t2 num2  ..

原创 POJ1426 Find The Multiple 深搜/廣搜

Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representat

原创 POJ2482 Stars in Your Window

Description (一段令人感動的程序員的愛情故事...) Here comes the problem: Assume the sky is a flat plane. All the stars lie on it with

原创 POJ1001 Exponentiation 高精度

求高精度冪 Description 對數值很大、精度很高的數進行高精度計算是一類十分常見的問題。比如,對國債進行計算就是屬於這類問題。  現在要你解決的問題是:對一個實數R( 0.0 < R < 99.999 ),要求寫程序精確計算 R

原创 POJA2488 Knight's Journey 深搜DFS

A Knight's Journey   Description Background  The knight is getting bored of seeing the same black and white squares aga

原创 POJ2386 Lake Counting 深度優先搜索

poj2386 Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represente

原创 POJ 1151 Atlantis 線段樹+離散化+掃描線

Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of thes

原创 POJ3177 Redundant Paths邊雙連通分量

http://poj.org/problem?id=3177題意:有F個牧場(1<=F<=5000),現在一個牧羣經常需要從一個牧場遷移到另一個牧場。奶牛們已經厭煩老是走同一條路,所以有必要再新修幾條路,這樣它們從一個牧場遷移到另一個牧場

原创 POJ1144 Network 割點

NetworkDescriptionA Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting sev

原创 POJ 2485 Highways Kruskal最小生成樹

HighwaysDescriptionThe island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So

原创 POJ2186 Popular Cows 強連通分量tarjan算法

http://poj.org/problem?id=2186題意:n頭奶牛給出m組歡迎關係 a,b 表示a歡迎b,歡迎關係時單向、傳遞的,求出被所有的奶牛歡迎的奶牛的數目。分析:可將題目轉換爲N個頂點M條邊的有向圖,求有多少點可以由其餘任