原创 uva-11987 Almost Union-Find (並查集)

題意:      初始給定n個集合:{1},{2},…,{n},要求支持三種操作:       "1 p q":若p,q不在同一集合,將它們所在的集合合併成一個       "2 p q":若p,q不在同一集合,將元素p移動到q所在的集合

原创 POJ 3255 Roadblocks --次短路 + spfa

Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to

原创 poj1149--PIGS (網絡最大流,Ford-Fulkerson算法 和 dinic算法)

Mirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't h

原创 hdu1711 Number Sequence 【kmp】

Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1

原创 LightOJ 1024 - Eid (高精度乘法求n個數的LCM)

In a strange planet there are n races. They are completely different as well as their food habits. Each race has a food

原创 LightOJ - 1007 Mathematically Hard (歐拉打表+前綴和)

Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable. In thi

原创 hdu 2177-取(2堆)石子游戲(威佐夫博弈)

有兩堆石子,數量任意,可以不同。遊戲開始由兩個人輪流取石子。遊戲規定,每次有兩種不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在兩堆中同時取走相同數量的石子。最後把石子全部取完者爲勝者。現在給出初始的兩堆石子的數目,如果輪到

原创 快速冪模板

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int pow_mod(int a,int b) { int res=1

原创 POJ 3070 Fibonacci [矩陣快速冪模板]

In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms

原创 POJ - 2406 Power Strings

Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "

原创 HDU - 1754 I Hate It 【點修改】

很多學校流行一種比較的習慣。老師們很喜歡詢問,從某某到某某當中,分數最高的是多少。 這讓很多學生很反感。 不管你喜不喜歡,現在需要你做的是,就是按照老師的要求,寫一個程序,模擬老師的詢問。當然,老師有時候需要更新某位同學的成績。 Inpu

原创 LightOJ - 1234 I - Harmonic Number

In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers: In this proble

原创 LightOJ - 1245 G - Harmonic Number (II)

I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int n ) {     long lon

原创 LightOJ - 1138 N - Trailing Zeroes (III)

You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. A

原创 HDU - 1251 F - 統計難題

Ignatius最近遇到一個難題,老師交給他很多單詞(只有小寫字母組成,不會有重複的單詞出現),現在老師要他統計出以某個字符串爲前綴的單詞數量(單詞本身也是自己的前綴).  Input 輸入數據的第一部分是一張單詞表,每行一個單詞,單詞