原创 CSU1604 sunnypig

Description SunnyPig is a pig who is much cleverer than any other pigs in the pigpen. One sunny morning, SunnyPig wan

原创 POJ 1041 John's trip(歐拉回路)

題意已經告訴我們圖是連通的,所以只要判斷每個點的度是否爲偶數即可。 #include<stdio.h> #include<string.h> #include<vector> #include<algorithm> #include<

原创 hdu1044 Collect More Jewels

Problem Description It is written in the Book of The Lady: After the Creation, the cruel god Moloch rebelled against

原创 hdu1181 變形課

這道題真心沒什麼好說的,直接深搜。但是我竟然WA了10次,知道爲什麼嗎?因爲我把輸出結果的Yes打成了YES。剛接觸ACM的時候纔會犯的錯誤啊! #include<stdio.h> #include<string.h> char a[3

原创 hdu1180 詭異的樓梯

這道題其實就是在BFS基礎上的一個變形。要注意的細節是到達樓梯前若不能通過,可以選擇停留在原地等樓梯轉過來再過去,要把這種情況考慮進去。還有就是用當前的步數和樓梯的初始狀態來判斷樓梯此時的狀態。另外一點就是樓梯所在的位置不需要判重,因爲我

原创 最短路模板總結(不定時更新)

我用的是鄰接表構圖。 一,dijstar的優先隊列優化(附打印路勁) const int N=1100; int head[N],cnt; int d[N],pre[N]; struct node {     int u,d;    

原创 HDU 2680(spfa)

題意:有多個起點,求到終點的最短路,一個個求的話很明顯會超時。有兩種寫法: 一,構建一個超級源點,與起點相連,距離爲0,從0開始搜。然後套模板即可。 二,構建反向圖,以終點爲起點開始搜。 下面是我用第一種思路套的spfa 的模板。。寫的有

原创 HDU 1142(djstar+記憶化搜索)

題意不是問最短路有多少條,而是問從下一個點出發有多少條路比從當前點出發到2(終點)要短??   最短路算法方面是直接套用的模板,不過這次不是先求終點到各點的最短路,再從源點進行搜索。 #include<stdio.h> #include

原创 hdu1195 Open the Lock

一次AC,我以爲會超呢。 #include<stdio.h> #include<string.h> #include<queue> #include<iostream> using namespace std; int s,e,mark

原创 HDU 1166 樹狀數組

以前用線段樹寫的,編碼複雜,效率也低。今天剛學習了樹狀數組,發現這道題可以用樹狀數組來寫,而且時間也節省了一半,編碼複雜度和空間複雜度就更不用說了。 #include<stdio.h> #include<string.h> #defin

原创 ACM感想

      從進入大學到軍訓結束,我都處在一個對接下來的人生的一個探索階段,尤其是軍訓結束後,少了學長學姐和輔導員的管束,生活作息越來越亂,本來挺直的肩膀也變得微躬。就在這個堪稱我大學生涯甚至整個人生生涯的轉折點,王老師和工作室的學長學姐

原创 二分圖最大匹配算法-Hopcroft-Karp模板

#include<stdio.h> #include<string.h> const int N=500,M=500,INF=0x3f3f3f3f; int dx[N],dy[M],sx[N],sy[M],p[N],q[N],a[N][M

原创 快速冪

int pow(int a,int b,int mod) { int ans=1; a=a%mod; while(b) { if(b&1) ans=(ans*a)%mod; a=(a*a)%mod; b=b>>1

原创 LIS(最長上升子序列)模板

int LIS(const int a[],int n) { int lis[n],pre[n],js=1; lis[1]=1; for(int i=2;i<=n;i++) { int l=1,r=js,m; while(

原创 HDU 3605(多重最大匹配)

#include<stdio.h> #include<string.h> const int N=1e5+11,M=11; int a[N][M],match[M][N],cnt[M],cap[M],p[M]; int n,m; inli