這題的技巧就是:枚舉---旋轉(zhuǎn)卡殼法。 題目大意: 每頭牛對每個谷倉有一個喜歡程度,F(xiàn)J的目的就是要使得每頭牛的happy盡可能的相同,求最小的范圍。 這題的枚舉還是很有技巧的。雖然知道怎么來滑動窗口。 但是我的網(wǎng)絡(luò)流EK算法太不給力了! 沒辦法.. 去學(xué)
這題的技巧就是:枚舉---旋轉(zhuǎn)卡殼法。
題目大意:
每頭牛對每個谷倉有一個喜歡程度,F(xiàn)J的目的就是要使得每頭牛的happy值盡可能的相同,求最小的范圍。
這題的枚舉還是很有技巧的。雖然知道怎么來滑動窗口。 但是我的網(wǎng)絡(luò)流EK算法太不給力了!
沒辦法.. 去學(xué)習(xí)了下SAP勉強(qiáng)把這題切掉了= =
#include#include #include #include #define MN 1111 #define INF 0x0FFFFFFF #define CC(m,what) memset(m,what,sizeof(m)) #define FOR(i,a,b) for( int i = (a) ; i < (b) ; i ++ ) #define FF(i,a) for( int i = 0 ; i < (a) ; i ++ ) #define FFD(i,a) for( int i = (a)-1 ; i >= 0 ; i --) #define SS(a) scanf("%d",&a) #define LL(a) ((a)<<1) #define RR(a) (((a)<<1)+1) #define SZ(a) ((int)a.size()) #define PP(n,m,a) puts("---");FF(i,n){FF(j,m)cout << a[i][j] << ' ';puts("");} #define read freopen("in.txt","r",stdin) #define write freopen("out.txt","w",stdout) #define two(x) ((LL)1<<(x)) #define include(a,b) (((a)&(b))==(b)) template inline T countbit(T n) {return n?1+countbit(n&(n-1)):0;} template inline T sqr(T a) {return a*a;} template inline void checkmin(T &a,T b) {if(a == -1 || a > b)a = b;} template inline void checkmax(T &a,T b) {if(a < b) a = b;} using namespace std; struct EDGE { int u,v,len; }edge[1000*21]; int map[MN][MN],vis[MN],barn[MN],pre[MN]; int N,B,s,t,ans; bool cmp( EDGE a,EDGE b ){ return a.len dis[v] ) { cur[u]=v; mind=dis[v]; } if( (--gap[dis[u]])==0 ) break; gap[dis[u]=mind+1]++; u=pre[u]; } return maxflow; } bool work() { int i,j; if( sap()==N ) return true; else return false; } int main() { while( scanf("%d%d",&N,&B)!=EOF ) { setG(); int range=INF; int r=1,l=1; while( l<=B&&l<=r&&r<=B ) { initG(l,r); if( work() ) { range=min( range,r-l+1 ); l++; } else r++; } printf( "%d\n",range ); } return 0; }
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com