跳到主要內容

發表文章

目前顯示的是 3月, 2013的文章

uva 11099

這題難,用篩子法並且強化,把每個number的質因數相乘之後做排序,就可以得知下一個順序是哪位   2 4 8 16 32 ........3 6 9 所以如果下一個的質因數相乘不是上一個的話,就代表已經超過MAX範圍了 //============================================================================ // Name : Next Same-Factored.cpp // Date : 2013/3/30 上午12:42:53 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() prin

uva 10821

終於AC了 取值構樹,盡量往右邊塞 這樣頭才會最小 //============================================================================ // Name : Constructing BST.cpp // Date : 2013/3/29 下午3:30:27 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n" ) #define I_de(x,n) for (Int i=0;i<n;i++)prIntf( "%d " ,x

uva 10573

這題有點賤,有可能輸入會有一個或兩個的情況,給切線長度或兩個r //============================================================================ // Name : Geometry Paradox.cpp // Date : 2013/3/28 下午10:26:00 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n" ) #define I_de(x,n) for ( int i=0;i<n;i++)printf( "%d &

uva 148

這題有點奇怪,陣列開得剛剛好 結果RE了 但是限制不是只有20個字嗎,還是我搞錯題意了... //============================================================================ // Name : Anagram checker.cpp // Date : 2013/3/28 上午10:46:49 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> #include <sstream> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n" ) #define I_de(x,n) for

uva 10171

求最短路徑的變化題,用了floyd 有一些特殊情況需要設置,然後就AC了 //============================================================================ // Name : Meeting Prof. Miguel.cpp // Date : 2013/3/24 下午10:22:31 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n" ) #define I_de(x,n) for ( int i=0;i<n;i++)printf(

uva 10048

蠻白吃的 本來還想要用priority queue做 結果有點失誤 索性用找的,最後一次AC了 //============================================================================ // Name : Audiophobia.cpp // Date : 2013/3/24 下午12:17:50 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n" ) #define I_de(x,n) for ( int i=0;i<n;i++)printf

uva 575

水題,本來以為直觀這樣打會TLE 結果還是AC了 //============================================================================ // Name : Skew Binary.cpp // Date : 2013/3/23 下午8:51:25 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n" ) #define I_de(x,n) for ( int i=0;i<n;i++)printf( "%d " ,x[i]);

uva 11234

用queue表演出stack 很像是括號匹配的感覺,不過想破頭還是無法想出來 最後參考了網路上的解題報告,原來stack跟queue有一個有趣的關係,利用樹 //============================================================================ // Name : Expressions.cpp // Date : 2013/3/23 下午12:21:44 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n&quo

uva 12493

本來以為是一筆畫圖形,結果完全不是... 因為要走完所有的點 而且每一步都是一樣長的,所以走的步數要跟總共的點互質 否則最大公因數如果不是1代表不到n步就走完了   其實是歐拉公式 取出n的所有質因數a1,a2,a3 並且用公式n2=n(1-1/a1)*(1-1/a2)*(1-1/a3) 這就等於把質因數全部的倍數刪掉 取出剩下的數 //============================================================================ // Name : stars2.cpp // Date : 2013/3/22 上午11:47:39 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) fre

uva 10287

麻煩的數論,四個圈圈尤其難算,用了正弦 餘弦定理解決了 //============================================================================ // Name : Gifts in a Hexagonal Box.cpp // Date : 2013/3/20 下午6:31:43 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n" ) #define I_de(x,n) for ( int i=0;i<n;i++)printf( "%

ICPC 2012 Latin America Regional – uva 12530

這題根本屌題,雖然看起來像是博弈題,不過可以用完美匹配來解決他 只要找出一個地區(連通)用黑白色來染每一格,然後只要是(二分圖)完美匹配代表先手怎麼放,後手怎麼放都OK 那就是完美匹配,不過如果一不是完美匹配,那就代表一定有一個位置放了之後後手穩輸 //============================================================================ // Name : Game of Tiles.cpp // Date : 2013/3/18 下午2:17:15 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln

ICPC 2012 Jakarta 6044 - Unique Path

這題只能說 我覺得很難 而且難到靠北,靠班上的牛人想法AC了 //============================================================================ // Name : 6044 - Unique Path.cpp // Date : 2013/3/17 下午3:35:38 // Author : GCA //============================================================================ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <set> #include <map> #include <queue> #include <cctype> #include <utility> using namespace std; #ifdef ONLINE_JUDGE #define ll "%lld" #else #define ll "%I64d" #endif typedef unsigned int uint; typedef long long int Int; #define Set(a,s) memset(a,s, sizeof (a)) #define Write(w) freopen(w, "w" ,stdout) #define Read(r) freopen(r, "r" ,stdin) #define Pln() printf( "\n" ) #define I_de(x,n) for ( int i=0;i<n;i++)printf( "%d &