最小费用最大流 源点->警察->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. MongoDb第一天

    安装之后进入cmd.进入到安装目录下的bin目录下. 任意选一个空目录,建立db,log的文件夹.之后终端命令行里面输入回车. D:\ProgramFiles\MongoDB\Server\3.6\b ...

  2. Windows Server 远程桌面连接不上问题解决

    关于Windows Server 远程桌面连接不上的问题需要从服务.端口.防火墙这几方面进行检查: 服务器上需要 开启的服务: - Remote Access Auto Connection Mana ...

  3. 笔记-python-调试

    笔记-python-调试 一般在pycharm下调试或使用log查看输出日志,有时小程序不想这么麻烦,也有一些方便使用的调试方式可以使用. 1.      idle调试 1.打开Python shel ...

  4. Ubuntu 16.04上安装并配置Postfix作为只发送SMTP服务器

    如果大家已经在使用第三方邮件服务方案发送并收取邮件,则无需运行自己的邮件服务器.然而,如果大家管理一套云服务器,且其中安装的应用需要发送邮件通知,那么运行一套本地只发送SMTP服务器则更为理想. 如何 ...

  5. 6.Mongodb索引

    1.索引 2.索引的命令

  6. linux socket下send()&recv()调用

    1.send 函数 int send( SOCKET s, const char FAR *buf, int len, int flags ); 不论是客户还是服务器应用程序都用send函数来向TCP ...

  7. javaWEB简单商城项目

    javaWEB简单商城项目(一) 项目中使用到了上一篇博文的分页框架,还有mybatis,重点是学习mybatis.现在有些小迷茫,不知道该干啥,唉,不想那么多了,学就对了 一.项目功能结构 1.功能 ...

  8. 玩转Node.js(三)

    玩转Node.js(三) 上一节对于Nodejs的HTTP服务进行了较为详细的解析,而且也学会了将代码进行模块化,模块化以后每个功能都在单独的文件中,有利于代码的维护.接下来,我们要想想如何处理不同的 ...

  9. 【Pascal's Triangle II 】cpp

    题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...

  10. Class对象和反射

    1.class对象在java中一切都是对象,从某种意义上,java中的对象可以分为:实例对象和Class对象.实例对象通过new关键得到,那么Class对象呢?Class对象无法通过new关键字获取, ...