UVA 10746 Crime Wave - The Sequel
最小费用最大流 源点->警察->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的更多相关文章
- uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)
option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ...
- UVa 488 - Triangle Wave
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...
- UVA 488 - Triangle Wave 水~
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
- 【索引】Volume 0. Getting Started
AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 0. Getting Started 10055 - Hashmat the Brav ...
- RIFF和WAVE音频文件格式
RIFF file format RIFF全称为资源互换文件格式(Resources Interchange File Format),是Windows下大部分多媒体文件遵循的一种文件结构.RIFF文 ...
- IEEE 802.11p (WAVE,Wireless Access in the Vehicular Environment)
IEEE 802.11p(又称WAVE,Wireless Access in the Vehicular Environment)是一个由IEEE 802.11标准扩充的通讯协定.这个通讯协定主要用在 ...
- Wave - 花たん 音乐
Wave 歌手:花たん 所属专辑:Flower 間違えて宇宙終わって(宇宙因为一个错误而终结了) 青信号はいつも通り(通行的灯号一如往常的) 飛んでまた止まって(又再停止传播) また 飛びそうだ(然后 ...
随机推荐
- MySQL触发器和更新操作
一.触发器概念 触发器(trigger):监视某种情况,并触发某种操作,它是提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊的存储过程,它的执行不是由程序调用,也不是手工启动 ...
- android gridview 停止滚动
http://blog.csdn.net/yaphetzhao/article/details/50544105 参考上面的博客,关键代码我就贴出来吧: public void stopGridVie ...
- erlang中的原子(atom)内部实现[转]
转自: http://www.kongqingquan.com/archives/208#more-208 Erlang中的atom由通用hash表实现,虚拟机中atom最终的用数值表示,对应表中的下 ...
- 站在C#和JS的角度细谈函数式编程与闭包
1.函数式编程是什么? 摘自百度的说法是.函数式编程是种编程典范,它将电脑运算视为函数的计算.函数编程语言最重要的基础是 λ 演算(lambda calculus).而且λ演算的函数可以接受函数当作输 ...
- 剑指Offer - 九度1362 - 左旋转字符串(Move!Move!!Move!!!)
剑指Offer - 九度1362 - 左旋转字符串(Move!Move!!Move!!!)2013-11-23 03:05 题目描述: 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任 ...
- 【UVA10655】 Contemplation! Algebra
题目 给定 \(p = a + b\) 和 \(q = ab\) 和 \(n\),求 \(a ^ n + b ^ n\). $0\le n\lt 2^{63} $ 分析 大水题. 先考虑 \(n\) ...
- centos6安装openfire(mysql)
一.安装JDK 我的系统是centos6.8x64,首先安装jdk1.7.0 二.安装openfire 我装的包是:openfire-3.9.3-1.i386.rpm,复制到/opt目录 #rpm - ...
- java程序员笑不死的经历ส้้้้้้้้้
ส้้้้้้้้้้ส้้้้้้้้้้ส้้้้้้้้้ 1.程序猿最烦两件事,第一件事是别人要求他给自己的代码写文档,第二件呢?是别人的程序没有留下文档. 2.宪法顶个球!中国的法律都是.t ...
- c++知识点总结--静态与动态联编
静态联编是指在编译阶段就将函数实现和函数调用关联起来,因此静态联编也叫早绑定,在编译阶段就必须了解所有的函数或模块执行所需要检测的信息,它对函数的选择是基于指向对象的指针(或者引用)的类型 动态联 ...
- Spring 笔记(四)AOP
前言 横切关注点 使用 @AspectJ 定义切面. 同时还需要在配置类上应用 @EnableAspectJAutoProxy 注解,启用 AOP 自动代理.(不添加它的话,@AspectJ 注解的类 ...