原创 [HDU] 1879 繼續暢通工程

題目: 省政府“暢通工程”的目標是使全省任何兩個村莊間都可以實現公路交通(但不一定有直接的公路相連,只要能間接通過公路可達即可)。現得到城鎮道路統計表,表中列出了任意兩城鎮間修建道路的費用,以及該道路是否已經修通的狀態。現請你編

原创 [UVA] 11059 Maximum Product

題目分析:暴力,直接枚舉起點和終點,乘積最大不超過10的18次方,可以用long long 存下。 題目代碼: #include<iostream> #include<cstdio> #include<cstring> usin

原创 [CSU] 1087 就多了兩分鐘

題目: Yucept21和他的室友Zyn因爲宿舍沒電去網吧上網,上了27分鐘,Cs打電話來說來電了。所以Yucept21在第29分鐘下機了,上網的費用是一塊錢,然後Zyn墨跡了兩分鐘,第31分鐘下機,上機費用是2元。現在知道網

原创 [紫書] 生成1~n的全排列

1.作用:輸入n,輸出1-n的全排列,無可重集。 代碼: #include<iostream> #include<cstdio> using namespace std; void print_permutation(int

原创 [CodeForces]-675B-Restoring Painting

B - Restoring Painting Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status

原创 [Aha]擒賊先擒王

題目:詳見啊哈算法P200頁。就是並查集的裸題。 分析:裸題呀,理解並背下代碼。 代碼: #include<iostream> #include<cstdio> #include<cstring> using namespac

原创 [Aha]火柴棍等式

題目詳見:啊哈算法P67頁。 題目分析:看到應該首先想到暴力,關鍵是如何想到只用暴力到1111。 代碼: #include<iostream> #include<cstdio> using namespace std; i

原创 [UVA] 10976 Fractions Again?!

題目分析:暴力一下,還有判斷除數是否爲整數直接取餘一下就好了。關鍵是分析出y<=k*2; 題目代碼: #include<iostream> #include<cstdio> #include<cstring> #include<a

原创 [Aha]坑爹的奧數

題目:見啊哈算法p58頁,一開始用暴力枚舉的方式寫的,後p79頁介紹如何使用DFS做。很適合熟悉DFS的寫法。 分析:按照套路來 void dfs(int step){ 判斷邊界; 嘗試每一種可能for(int

原创 [Aha]解救小哈

題目:見啊哈算法P81頁。 分析:最常見的DFS配合最短路,熟悉寫法。 代碼: #include<iostream> #include<cstdio> using namespace std ; int n , m , p

原创 [Aha]圖的深度優先遍歷

題目:詳見啊哈算法P131頁。就是如何給一個圖,然後進行深度優先遍歷。 分析:DFS入門。 代碼: #include<iostream> #include<cstdio> #include<cstring> using nam

原创 [UVA] 540 Team Queue

題目: Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, howeve

原创 [UVA] 10815 Andy's First Dictionary

題目: Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the numbe

原创 [HDU] 1754 I Hate It

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

原创 [CF] 787A The Monster

題目: A monster is chasing after Rick and Morty on another planet. They’re so frightened that sometimes they scream. Mor