原创 POJ 1306

#include<iostream> #include<string.h> //#include<mylib.h> #define size 10010 using namespace std; class Union{ pr

原创 獲得第k小元素

分治,關鍵是用到快拍的時候的partation函數 #include<iostream> #include<hash_map> #include<string> #include<iterator> #include<algorithm

原创 【數論】一個公式,a^p mod m,求逆元

//擴展歐幾里得 long long exgcd(long long a,long long b,long long &x,long long &y) { if(a==0){ x=0; y=1; return b; } lon

原创 POJ 1195

#include<iostream> #include<cstring> #include<string> #include<cstdio> using namespace std; template<class ValueType,in

原创 【數論】擴展歐幾里得 Ax+By=m 最小的X

#include<iostream> #include<stdio.h> using namespace std; //#include<mylib.h> //擴展歐幾里得 long long exgcd(long long a,lo

原创 POJ 1182

搞了n久才明白啥意思。。。 代碼參考:http://www.slyar.com/blog/poj-1182-c.html #include<iostream> #include<hash_map> //#include"iphxer_h.

原创 並查集

class Union{ private: int *father; int *rank; int _size; public: Union(int _size)

原创 NOJ 141

#include<iostream> #include<string.h> #include<assert.h> using namespace std; //hashmap template<class KeyType,int MaxH

原创 編譯原理 計算等價集合的個數

/* 問題: 編譯原理中將一個不確定性自動機轉化成確定性自動機的過程中 個個等價集合。 輸入格式: 第一行有一個整數n表示有n個狀態(S0到Sn-1),隨後的每一行第一個是一個整數m,表示狀態Sm 第二個是一個字符s(如果

原创 NOJ 123 樹狀數組 插線問點

#include<iostream> #include<cstring> #include<cstdio> #include<string> using namespace std; #define _size 1000010 int

原创 POJ 1456 並查集的又一種用法

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define _size 100010 str

原创 人工智能 a b c 說謊問題

上午寫的時候條件弄錯了,一直無解……改過條件後不知道這樣寫對不對,期待指正。 /* 題目描述: a: b,c 說的是真話 b: a,c 說的是假話 c: a,b 至少有一個說的是假話 此題只要找出誰是說真話的即可。分別假設各個說

原创 NOJ 147

#include<iostream> #include<stdio.h> using namespace std; //#include<mylib.h> //擴展歐幾里得 long long exgcd(long long a,lo

原创 NOJ 214

主要一個獲得第一個大於目標值的位置 #include<iostream> #include<algorithm> #include<iterator> #include<cstdio> using namespace std; #defi

原创 0-1揹包作業 動態規劃

/* 0-1 揹包問題 n個物品,最大容量(或者質量)爲w的包,體積(或質量),價值分別爲vi,pi(0<=i<n); 動態規劃解法 動態轉移方程 f(n,w)=max{f(n-1,w),f(n-1,w-v[n])+p[n]}