UVA 10330 Power Transmission
题意:懒得打了。LUCKY CAT 里有 http://163.32.78.26/homework/q10330.htm
第一个网络流题目。每个节点都有一个容量值。需要拆点。拆成i - > i + N 边权为容量值
另外注意B个点 连接方式:s - 集合B
D个点 链接方式 集合D + N -> t汇点
其他看处理就好
- #include <map>
- #include <set>
- #include <list>
- #include <cmath>
- #include <ctime>
- #include <deque>
- #include <stack>
- #include <queue>
- #include <cctype>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <climits>
- #include <cstdlib>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- #define LL long long
- #define PI 3.1415926535897932626
- using namespace std;
- int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
- #define MAXN 250
- const int INF = 0x3f3f3f3f ;
- int flow[MAXN][MAXN],c[MAXN][MAXN];
- int p[MAXN];
- int N,M,B,D,src,tag;
- void read()
- {
- memset(c,,sizeof(c));
- src = ; tag = * N + ;
- for (int i = ; i <= N; i++)
- {
- int tmp;
- scanf("%d",&tmp);
- c[i][i + N] = tmp;
- }
- scanf("%d",&M);
- for (int i = ; i <= M; i++)
- {
- int u,v,w;
- scanf("%d%d%d",&u,&v,&w);
- c[u + N][v] = w;
- }
- scanf("%d%d",&B,&D);
- for (int i = ; i <= B; i++)
- {
- int tmp;
- scanf("%d",&tmp);
- c[][tmp] = INF;
- }
- for (int i = ; i <= D; i++)
- {
- int tmp;
- scanf("%d",&tmp);
- c[tmp + N][tag] = INF;
- }
- }
- int Edmonds_karp(int src,int tag)
- {
- memset(flow,,sizeof(flow));
- int ans = ;
- queue<int>q;
- while (!q.empty()) q.pop();
- int a[MAXN];
- while (true)
- {
- memset(a,,sizeof(a));
- a[src] = INF;
- q.push(src);
- while (!q.empty())
- {
- int u = q.front(); q.pop();
- for (int v = ; v <= tag; v++)
- if (!a[v] && c[u][v] > flow[u][v])
- {
- p[v] = u;
- q.push(v);
- a[v] = min(a[u],c[u][v] - flow[u][v]);
- }
- }
- if (a[tag] == ) break;
- for (int u = tag; u != src; u = p[u])
- {
- flow[p[u]][u] += a[tag];
- flow[u][p[u]] -= a[tag];
- }
- ans += a[tag];
- }
- return ans;
- }
- int main()
- {
- //freopen("sample.txt","r",stdin);
- while (scanf("%d",&N)!=EOF)
- {
- read();
- printf("%d\n",Edmonds_karp(src,tag));
- }
- return ;
- }
UVA 10330 Power Transmission的更多相关文章
- uva 10330 - Power Transmission(网络流)
uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...
- UVa 10330 - Power Transmission(最大流--拆点)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 10330 Power Transmission / 最大流
最大流 这题有很多起点和终点 在取2个点(0和n+1) 作为唯一的起点和终点 此外每个点也有容量限制 建图时每条边上的容量为这条边和2个端的容量的最小值 然后EK就行 #include <cst ...
- light oj 1155 - Power Transmission【拆点网络流】
1155 - Power Transmission PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- UVA 11149 - Power of Matrix(矩阵乘法)
UVA 11149 - Power of Matrix 题目链接 题意:给定一个n*n的矩阵A和k,求∑kiAi 思路:利用倍增去搞.∑kiAi=(1+Ak/2)∑k/2iAi,不断二分就可以 代码: ...
- C2. Power Transmission (Hard Edition)(线段相交)
This problem is same as the previous one, but has larger constraints. It was a Sunday morning when t ...
- C2. Power Transmission (Hard Edition) 解析(思維、幾何)
Codeforce 1163 C2. Power Transmission (Hard Edition) 解析(思維.幾何) 今天我們來看看CF1163C2 題目連結 題目 給一堆點,每兩個點會造成一 ...
- UVA 11149.Power of Matrix-矩阵快速幂倍增
Power of Matrix UVA - 11149 代码: #include <cstdio> #include <cstring> #include < ...
- UVa 11149 Power of Matrix(倍增法、矩阵快速幂)
题目链接: 传送门 Power of Matrix Time Limit: 3000MS Description 给一个n阶方阵,求A1+A2+A3+......Ak. 思路 A1+A2+. ...
随机推荐
- poj 2674 线性世界 弹性碰撞
弹性碰撞的题目一般都是指碰到就会掉转方向的一类题目,这里我们可以忽略掉头,仅仅看成擦肩而过,交换名字等等 题意:一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的名 ...
- Servlet HttpRequest 中【getAttribute】和【getParameter】的区别
1.获取的值不同 getAttribute表示从request范围取得设置的属性,必须要通过setAttribute设置属性,才能通过getAttribute取得.设置和取得的值都是Object类型. ...
- Personal Collection
1.常用网站 序号 网址 标题 1 https://www.oschina.net/ 开源软件 2 http://tool.oschina.net/ 开发常用工具网站 3 https://docs.o ...
- C# WinForms跨线程更新 UI
与在Android中一样, 子线程中更新UI被认为是线程不安全的, 会抛出异常. 子线程返回UI线程中更新UI的一个方法为: 1, 捕获应用的UI线程的上下文; 2, 定义线程任务; 3, 定义线程任 ...
- Dapper基础增删查改、事务和存储过程
1.前言 Dapper是一个轻量级的orm框架,上手也非常的简单,它可以实体映射,所以先准备实体如下: public class Couser { public int id { get; set; ...
- PaaS服务之路漫谈(一)
此文已由作者尧飘海授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. PaaS服务之路漫谈(一) 1983年,SUN公司提出的网络即计算的理念:2006年亚马逊(Amazon)推 ...
- ptmalloc,tcmalloc和jemalloc内存分配策略研究 ? I'm OWen..
转摘于http://www.360doc.com/content/13/0915/09/8363527_314549949.shtml 最近看了glibc的ptmaoolc,Goolge的tcmall ...
- Python爬虫教程
Python爬虫(1):基本原理 Python爬虫(2):Requests的基本用法 Python爬虫(3):Requests的高级用法 Python爬虫(4):Beautiful Soup的常用方法 ...
- install ironic-inspector
安装相应的包和组件 yum install openstack-ironic-inspector python-ironic-inspector-client -y 创建user openstack ...
- Small组件化重构安卓项目
如果从一开始就没有设计好 后面项目业务比较大的时候很难掉头