最小费用最大流 源点->警察->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. 笔记-爬虫-去重/bloomfilter

    笔记-爬虫-去重/bloomfilter 1.      去重 为什么要去重? 页面重复:爬的多了,总会有重复的页面,对已爬过的页面肯定不愿意再爬一次. 页面更新:很多页面是会更新的,爬取这种页面时就 ...

  2. 笔记-爬虫-模拟登录github

    笔记-模拟登录github 1.      模拟登录github 1.1.    环境准备 安装/升级requests 2.20.0 pip install --upgrade requests pi ...

  3. setBackgroundResource和setImageResource的区别

    setBackgroundResource是设置view的背景图片 setImageResource是设置ImageView的图片 对于一个imagevewButton来说,你既可以setBackgr ...

  4. laravel5.5入口文件分析

    入口文件 public/index.php 1.加载composer的自动加载器 require __DIR__.'/../vendor/autoload.php'; 自动加载,不用再各种requir ...

  5. 忙着Windows 10迁移?不要忘记Windows 7的安全!

    许多企业已经开始准备向Windows 10迁移了,对于IT管理员来说,Windows 7的安全性不容忽视. 自微软正式停止Windows 7主流支持至今刚刚超过一年,并且其扩展支持将于2010年结束. ...

  6. fix34

    public int[] fix34(int[] nums) { int i3=0; int i4=0; int temp=0; while( (i3<nums.length)&& ...

  7. 剑指Offer - 九度1352 - 和为S的两个数字

    剑指Offer - 九度1352 - 和为S的两个数字2014-02-05 18:15 题目描述: 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于 ...

  8. Json 转换 1 转成 true 0 转成false

  9. HTML5新增属性学习笔记

    1.form属性 表单内的从属元素,可以写在表单外部.可以通过指定元素的form属性来声明元素所属表单.form的属性值为表单的id. <form id="testForm" ...

  10. Python全栈工程师(递归函数、闭包)

    ParisGabriel            每天坚持手写  一天一篇  决定坚持几年 全栈工程师     Python人工智能从入门到精通 函数式编程: 是指用一系列函数解决问题 每一个函数完成细 ...