原创 Gym 100269D Dwarf Tower spfa/特殊最短路

特殊的輸入輸出,要用文件來進行。 輸出用cout以刷新緩衝區。 建圖之後,其他就是spfa板子了。 #include <cstdio> #include <algorithm> #include <cmath> #include

原创 HDU 5242 Game (貪心/思維)

It is well known that Keima Katsuragi is The Capturing God because of his exceptional skills and experience in ‘‘c

原创 CodeForces 1201C C. Maximum Median(思維)

You are given an array aa of nn integers, where nn is odd. You can make the following operation with it: Choose on

原创 HDU 2196 Computer(雖然理論上是樹形DP,實際簡單深搜)

A school bought the first computer some time ago(so this computer’s id is 1). During the recent years the school b

原创 POJ 2182 Lost Cows // POJ 2828 Buy Tickets(線段樹/迷之bug)

這兩題思路與題目都差不多, 我的想法是開一個線段樹維護最小值,從後往前找,第一個爲0的值一定是最靠前的,返回其位置,將其置爲0x3f3f3f3f,然後把這個位置以後的值統統-1,繼續下一個循環。 好像只有我用這種思路。。。。。。

原创 hdu 3068 最長迴文 Manacher模板題

#include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <queue> #include <vector> #incl

原创 MEX-Query Gym 101237A 主席樹

主席樹裏每個值的位置存當前該值出現的最右位置。 如果head[r]的前綴主席樹中,某值最右位置<l,說明該沒有出現在l,r中。 所以主席樹維護區間最小值,如果左半值域的最小值<l,則說明左半值域有值未在l,r出現,則查詢左子樹;否

原创 CodeForces 1137B Camp Schedule kmp

第一次沒看懂題意,用的樸素字符串匹配,排列n個第二個字符串,直到第一個剩下的不足以構成第二個字符串,然後wa了。 實際上應該使用kmp的next數組,把第二個字符串的真前後綴相同部分減去掉,然後重複上述過程即可。 #include

原创 CodeForces 362D Fools and Foolproof Roads

首先,使用並查集和優先隊列,其次,注意價值的增加量取較小值,再者,幾個判斷no的情況。 #include <cstdio> #include <algorithm> #include <cmath> #include <cstri

原创 POJ 3252 Round Numbers (二進制/數位DP)

轉化爲二進制,進行dp, 記錄的內容是在pos位上x個0、y個1情況下的有效數字個數, pre消除前導0影響。 #include <cstdio> #include <algorithm> #include <cmath> #in

原创 poj 2318 TOYS 計算幾何(入門)+二分

基礎入門題,做法單一。 #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <queue> #include <v

原创 POJ 3134 Power Calculus

iddfs 逐層搜索深度 x=max(x,now); if(x*(1<<time)<n) {top--;return ;}//關鍵剪枝語句 #include <cstdio> #include <algorithm> #

原创 ZOJ 4016 Mergeable Stack (list)

mark一下list的用法,包括很好用的splice() #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <q

原创 藍橋試題 算法提高 和諧宿舍2

我的某室友學過素描,牆上有n張他的作品。這些作品都是寬度爲1,高度不定的矩形,從左到右排成一排,且底邊在同一水平線上。   宿舍評比就要來了,爲了及格,我們決定買不多於m塊的矩形木板,把這些作品和諧掉。要求木板也從左到右排成一排,

原创 HDU 5536 Chip Factory 01字典樹/卡常數

標準01樹,網上說O(n^3)能過,我寫的遞歸建樹超時辣雞題目 因爲有卡常數的成分在裏面,優化之後7S過,寫的複雜一點鐵定超時 #include <cstdio> #include <algorithm> #include <cm