BZOJ 1000 A+B Problem
来源:互联网 发布:时间自动同步软件 编辑:程序博客网 时间:2024/06/03 17:17
Description
输入两个数字,输出它们之和
【题目分析】
虽然这是一道水题,但是暗藏玄机。网络流才是正解,8ms迅速出解。其解法之快,令人感叹!!!!
【代码】
#include <cstdio>#include <iostream>#include <cstring>#define INF 1000000using namespace std;int u[501],v[501],h[501],ne[501],map[501],f[501];int n,m,en=0,S,T;void add(int a,int b,int r){ u[en]=a;v[en]=b;ne[en]=h[a];f[en]=r;h[a]=en++; u[en]=b;v[en]=a;ne[en]=h[b];f[en]=0;h[b]=en++;}bool tell(){ memset(map,-1,sizeof map); int que[501]; int head=0,tail=0; que[tail++]=S; map[S]=0; while (head<tail){ int u=que[head++]; for (int i=h[u];i!=-1;i=ne[i]){ if (map[v[i]]==-1&&f[i]){ map[v[i]]=map[u]+1; que[tail++]=v[i]; } } } if (map[T]!=-1) return true; else return false;}int zeng (int k,int now){ if (k==T) return now; int r=0; for (int i=h[k];i!=-1&&now>r;i=ne[i]){ if (map[k]+1==map[v[i]]&&f[i]!=0){ int t=zeng(v[i],min(now-r,f[i])); f[i]-=t;f[i^1]+=t;r+=t; } } if (!r) map[k]=-1; return r;}int dinic(){ int r=0,t; while (tell()) while (t=zeng(S,INF)) r+=t; return r; }int main(){ memset(h,-1,sizeof h); S=0;T=2; int a,b; scanf("%d%d",&a,&b); add(S,1,a),add(S,1,b),add(1,T,a),add(1,T,b); cout<<dinic()<<endl;}
2 0
- BZOJ 1000: A+B Problem
- BZOJ 1000 A+B Problem
- BZOJ 1000: A+B Problem
- BZOJ-1000 A + B Problem 丧心病狂
- 【BZOJ 3218】 a + b Problem
- BZOJ P1000:a+b problem
- BZOJ 3218/UOJ #77 a + b Problem
- problem 1000: A+B problem
- Problem 1000 A+B Problem
- Problem - 1000 A + B Problem
- 【bzoj 1000】A+B
- 1000 A+B Problem
- 1000 A+B Problem
- 1000 A + B Problem
- 1000 A+B Problem
- 1000 A + B Problem
- 1000:A+B problem
- 1000 A + B Problem
- 关于WebService的浅显认识
- DirectX 资源
- 从QWebView.load()(QWebFrame.load())切换到QNetworkAccessManager引起的CSS加载不了的问题记录
- c/c++ 管道编程
- ES6笔记(二)Promise对象
- BZOJ 1000 A+B Problem
- python的那些事——join()和"+"
- 算术编码转载1
- Android中Activity的finish()、destroy()、System.exit()区别
- Oracle学习笔记二----应用实践一
- Android基础知识回顾--Activity四种加载模式分析
- [Android]自定义View标题栏TitleBar
- quartz 时间配置规则
- Activity的生命周期