最小费用最大流 源点->警察->bank->汇点

剩下的模板就可以

#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 50
#define INF 100000000
const double eps = 1e- ;
int flow[MAXN][MAXN],cap[MAXN][MAXN];
double cost[MAXN][MAXN];
int N,M,src,tag;
double c;
int ans;
void read()
{
memset(cap,,sizeof(cap));
memset(flow,,sizeof(flow));
for (int i = ; i < MAXN; i++) for (int j = ; j < MAXN; j++) cost[i][j] = INF;
src = ; tag = N + M + ;
for (int i = ; i <= M; i++) {cap[][i] = ; cost[][i] = ;}
for (int i = ; i <= N; i++) {cap[M + i][tag] = ; cost[M + i][tag] = ;}
for (int i = ; i <= N; i++)
for (int j = ; j <= M; j++)
{
double tmp;
scanf("%lf",&tmp);
cost[j][i + M] = tmp;
cost[i + M][j] = -tmp;
cap[j][i + M] = ;
}
}
void slove()
{
queue<int>q;
bool inq[MAXN];
int p[MAXN];
double d[MAXN];
ans = ;
c = 0.0;
while (true)
{
memset(inq,false,sizeof(inq));
for (int i = ; i < MAXN; i ++) d[i] = INF;
d[src] = ;
q.push(src);
while (!q.empty())
{
int u = q.front(); q.pop();
inq[u] = false;
for (int v = ; v <= tag; v++)
if (cap[u][v] > flow[u][v] && d[v] > d[u] + cost[u][v] + eps)
{
d[v] = d[u] + cost[u][v];
p[v] = u;
if (!inq[v])
{
inq[v] = true;
q.push(v);
}
}
}
if (d[tag] == INF) break;
int a = INF;
for (int u = tag; u != src; u = p[u]) a = min(a,cap[p[u]][u] - flow[p[u]][u]);
for (int u = tag; u != src; u = p[u])
{
flow[p[u]][u] += a;
flow[u][p[u]] -= a;
}
c += d[tag] * a;
ans += a;
}
}
int main()
{
//freopen("sample.txt","r",stdin);
//freopen("output.txt","w",stdin);
while (scanf("%d%d",&N,&M) != EOF)
{
if (N == && M == ) break;
read();
slove();
printf("%.2lf\n",c / N + eps);
}
return ;
}

UVA 10746 Crime Wave - The Sequel的更多相关文章

  1. uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)

    option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ...

  2. UVa 488 - Triangle Wave

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...

  3. UVA 488 - Triangle Wave 水~

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. 一位学长的ACM总结(感触颇深)

    发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...

  6. 【索引】Volume 0. Getting Started

    AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 0. Getting Started 10055 - Hashmat the Brav ...

  7. RIFF和WAVE音频文件格式

    RIFF file format RIFF全称为资源互换文件格式(Resources Interchange File Format),是Windows下大部分多媒体文件遵循的一种文件结构.RIFF文 ...

  8. IEEE 802.11p (WAVE,Wireless Access in the Vehicular Environment)

    IEEE 802.11p(又称WAVE,Wireless Access in the Vehicular Environment)是一个由IEEE 802.11标准扩充的通讯协定.这个通讯协定主要用在 ...

  9. Wave - 花たん 音乐

    Wave 歌手:花たん 所属专辑:Flower 間違えて宇宙終わって(宇宙因为一个错误而终结了) 青信号はいつも通り(通行的灯号一如往常的) 飛んでまた止まって(又再停止传播) また 飛びそうだ(然后 ...

随机推荐

  1. 15.4,redis不重启,切换RDB备份到AOF备份

      确保redis版本在2.2以上 [root@pyyuc /data ::]#redis-server -v Redis server v= sha=: malloc=jemalloc- bits= ...

  2. Result Maps collection does not contain value for xxxx

    这是mybatis查询返回值的错误,我在做一个查询数值的方法,但是我是这样写的: <select id="findSize" resultMap="long&quo ...

  3. 为什么i=i++后,i的值不变(深入解析)

    在Java中,运行以下代码: int i=10; i=i++; System.out.println(i); 得到的结果仍然为10,为什么呢?理论上,运算的过程不应该是i首先把10取出来,赋值给i,然 ...

  4. Hyper-V中的Linux无法配置网络地址的解决办法

    一周碰到2次在Hyper-V 2012中安装了Linux,也安装了IC 3.4.但是却无法配置IP地址的问题.因此造成很多不便,因此找机会把这个原因和解决办法进行了尝试. 这过程中感谢同事的提示,让我 ...

  5. LDAP操作的两种方案

    最近由于项目需要研究了一下LDAP相关知识,感觉对没接触过的人来说还是有点坑的,所以记录下来给大家分享. 由于是第一次接触,就在网上搜了一些相关的文章,照着示例代码测试,却怎么也连不上LDAP服务器, ...

  6. 《Cracking the Coding Interview》——第2章:链表——题目7

    2014-03-18 02:57 题目:检查链表是否是回文的,即是否中心对称. 解法:我的做法是将链表从中间对半拆成两条,然后把后半条反转,再与前半条对比.对比完了再将后半条反转了拼回去.这样不涉及额 ...

  7. Jmeter的好搭档Badboy的安装与简单使用

    前提: Windows7  64位 Jdk 1.8 1.在官网上下载badboy并安装 网址:http://www.badboy.com.au/download/add 我下载的是最新的2.2.5这个 ...

  8. appium+python的APP自动化(1)

    写这个东西也是自己喜欢研究些自动化的东西,以下全是自己的经验所得,由于开源的软件对于各版本以及操作系统要求很高,会经常碰到一些不兼容的问题,这个都属于正常的,换版本就对了. 本人的环境搭建都是在win ...

  9. Leetcode 659.分割数组为连续子序列

    分割数组为连续子序列 输入一个按升序排序的整数数组(可能包含重复数字),你需要将它们分割成几个子序列,其中每个子序列至少包含三个连续整数.返回你是否能做出这样的分割? 示例 1: 输入: [1,2,3 ...

  10. 聊聊、Spring WebApplicationInitializer

    说到 WebApplicationInitializer,这个接口是为了实现代码配置 Web 功能.只要实现了这个接口,那么就可以实现 Filter,Servlet,Listener 等配置,跟在 x ...