这题的技巧就是:枚举---旋转卡壳法。 题目大意: 每头牛对每个谷仓有一个喜欢程度,FJ的目的就是要使得每头牛的happy尽可能的相同,求最小的范围。 这题的枚举还是很有技巧的。虽然知道怎么来滑动窗口。。 但是我的网络流EK算法太不给力了! 没办法.. 去学
这题的技巧就是:枚举---旋转卡壳法。
题目大意:
每头牛对每个谷仓有一个喜欢程度,FJ的目的就是要使得每头牛的happy值尽可能的相同,求最小的范围。
这题的枚举还是很有技巧的。虽然知道怎么来滑动窗口。。 但是我的网络流EK算法太不给力了!
没办法.. 去学习了下SAP勉强把这题切掉了= =
#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.lendis[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;
}
