标签:register display str max reg font ini struct main
★★☆ 输入文件:flyer.in
输出文件:flyer.out
简单对比
时间限制:1 s 内存限制:128 MB
1 #include <queue> 2 #include <ctype.h> 3 #include <cstdio> 4 #include <iostream> 5 6 using namespace std; 7 8 const int MAXN=10100; 9 const int INF=0x7fffffff; 10 11 int n,m,src,decc; 12 13 inline void read(int&x) { 14 register char c=getchar(); 15 for(x=0;!isdigit(c);c=getchar()); 16 for(;isdigit(c);x=x*10+c-48,c=getchar()); 17 } 18 19 struct node { 20 int to; 21 int next; 22 int val; 23 }; 24 node e[MAXN]; 25 26 int head[MAXN],cur[MAXN],tot=1; 27 28 int depth[MAXN]; 29 30 queue<int> q; 31 32 inline void add(int x,int y,int z) { 33 e[++tot].to=y; 34 e[tot].val=z; 35 e[tot].next=head[x]; 36 head[x]=tot; 37 } 38 39 bool bfs() { 40 for(int i=0;i<=tot;++i) depth[i]=-1,cur[i]=head[i]; 41 while(!q.empty()) q.pop(); 42 q.push(src); 43 depth[src]=0; 44 while(!q.empty()) { 45 int u=q.front(); 46 q.pop(); 47 for(int i=head[u];i!=-1;i=e[i].next) { 48 int to=e[i].to; 49 if(e[i].val&&depth[to]==-1) { 50 depth[to]=depth[u]+1; 51 q.push(to); 52 if(to==decc) return true; 53 } 54 } 55 } 56 return false; 57 } 58 59 int dfs(int now,int flow) { 60 if(now==decc) return flow; 61 int used=0,delat; 62 for(int &i=cur[now];i!=-1;i=e[i].next) { 63 int to=e[i].to; 64 if(e[i].val&&depth[to]==depth[now]+1) { 65 delat=flow-used; 66 delat=dfs(to,min(delat,e[i].val)); 67 used+=delat; 68 e[i].val-=delat; 69 e[i^1].val+=delat; 70 if(used==flow) break; 71 } 72 } 73 if(!used) depth[now]=-1; 74 return used; 75 } 76 77 int hh() { 78 // freopen("flyer.in","r",stdin); 79 // freopen("flyer.out","w",stdout); 80 int x,y,ans=0; 81 read(n);read(m); 82 decc=n+1; 83 fill(head,head+MAXN,-1); 84 for(int i=1;i<=m;++i) add(src,i,1),add(i,src,0); 85 while(scanf("%d%d",&x,&y)) add(x,y,1),add(y,x,0); 86 for(int i=m+1;i<=n;++i) add(i,decc,1),add(decc,i,0); 87 while(bfs()) ans+=dfs(src,INF); 88 printf("%d\n",ans); 89 /* for(int i=2;i<=tot;i+=2) { // 输出方案 逆向边有流量则有连边 90 if(e[i].to!=src&&e[i].to!=decc&&e[i^1].to!=src&&e[i^1].to!=decc) 91 if(e[i^1].val) printf("%d %d\n",e[i].to,e[i^1].to); 92 }*/ 93 return 0; 94 } 95 96 int sb=hh(); 97 int main() {;}
1 #include <cstdio> 2 #include <cstring> 3 4 const int MAXN=110; 5 6 int n,m; 7 8 int map[MAXN][MAXN],mark[MAXN]; 9 10 bool vis[MAXN]; 11 12 bool find(int x) { 13 for(int i=m+1;i<=n;++i) { 14 if(map[x][i]&&!vis[i]) { 15 vis[i]=true; 16 if(!mark[i]||find(mark[i])) { 17 mark[i]=x; 18 return true; 19 } 20 } 21 } 22 return false; 23 } 24 25 int hh() { 26 freopen("flyer.in","r",stdin); 27 freopen("flyer.out","w",stdout); 28 int x,y,ans=0; 29 scanf("%d%d",&n,&m); 30 while(scanf("%d%d",&x,&y)!=EOF) map[x][y]=1; 31 for(int i=1;i<=m;++i) { 32 memset(vis,false,sizeof vis); 33 if(find(i)) ans++; 34 } 35 printf("%d\n",ans);// 二分图匹配 方案容易输出 自己想吧 36 return 0; 37 } 38 39 int sb=hh(); 40 int main() {;}
标签:register display str max reg font ini struct main
原文地址:http://www.cnblogs.com/whistle13326/p/7348695.html