日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[bzoj1191][HNOI2006]超级英雄Hero

發(fā)布時間:2025/3/15 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [bzoj1191][HNOI2006]超级英雄Hero 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題意:有n個錦囊妙計,m道題。先從第1道題做起,每道題都有兩個妙計可以解決,解決之后才能進入下一題,每個妙計只能用一次,求最多能解決多少題

題解:二分答案+網(wǎng)絡(luò)流check

#include<cstdio> #include<iostream> #include<cstring> #include<queue> #define S 0 #define T 2001 using namespace std; inline int read() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}return x*f; }queue<int> qu; int cnt=1,n,m; int head[2005],q[2005]; struct edge{int to,next,w; }e[50005];void ins(int f,int t,int w){e[++cnt].next=head[f];head[f]=cnt;e[cnt].to=t;e[cnt].w=w;} void insw(int f,int t,int w){ins(f,t,w);ins(t,f,0);}int dfs(int x,int f) {if(x==T)return f;int used=0;for(int i=head[x];i;i=e[i].next)if(e[i].w&&q[e[i].to]==q[x]+1){int w=dfs(e[i].to,min(e[i].w,f-used));used+=w;e[i].w-=w;e[i^1].w+=w;if(f==used)return f;}return used; }bool bfs(int lim) {memset(q,0,sizeof(q));q[S]=1;qu.push(S);while(!qu.empty()){int x=qu.front();qu.pop();for(int i=head[x];i;i=e[i].next) if(e[i].w&&!q[e[i].to]&&(e[i].to-n<=lim||e[i].to==T)){q[e[i].to]=q[x]+1;qu.push(e[i].to);} }return q[T]>0; }bool check(int x) {int ans=0;for(int i=2;i<=cnt;i+=2) e[i].w=1,e[i^1].w=0;while(bfs(x))ans+=dfs(S,1000000);return ans==x; }int main() {n=read();m=read();for(int i=1;i<=n;i++)insw(S,i,1);for(int i=1;i<=m;i++)insw(read()+1,i+n,1),insw(read()+1,i+n,1),insw(i+n,T,1);int l=1,r=n,mid,ans=0;while(l<=r){mid=(l+r)>>1;if(check(mid))ans=mid,l=mid+1;else r=mid-1; }cout<<ans;return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/FallDream/p/bzoj1191.html

總結(jié)

以上是生活随笔為你收集整理的[bzoj1191][HNOI2006]超级英雄Hero的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。