费用流 建图很简单直接上代码

#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 110
#define MAXD 50000
const int INF = 0x3f3f3f3f;
int P,I;
int G[MAXN][MAXN];
queue<int>q;
struct node
{
int u,v,next;
int cap,flow,cost;
}edge[MAXD];
int cnt,src,tag;
int head[MAXN];
int p[MAXN],d[MAXN];
bool inq[MAXN];
int nump[MAXN],numi[MAXN];
void addedge(int u ,int v, int cap ,int cost)
{
edge[cnt].u = u;
edge[cnt].v = v;
edge[cnt].flow = ;
edge[cnt].cap = cap;
edge[cnt].cost = cost;
edge[cnt].next = head[u];
head[u] = cnt++; edge[cnt].v = u;
edge[cnt].u = v;
edge[cnt].flow= ;
edge[cnt].cap = ;
edge[cnt].cost = - cost;
edge[cnt].next = head[v];
head[v] = cnt++;
}
bool SPFA(int s,int t)
{
while (!q.empty()) q.pop();
memset(inq,false,sizeof(inq));
memset(d,0x3f,sizeof(d));
memset(p,-,sizeof(p));
inq[s] = true; d[s] = ;
q.push(s);
while (!q.empty())
{
int u = q.front();q.pop();
inq[u] = false;
for (int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if (d[v] > d[u] + edge[i].cost && edge[i].cap > edge[i].flow)
{
d[v] = d[u] + edge[i].cost;
p[v] = i;
if (!inq[v])
{
inq[v] = true;
q.push(v);
}
}
}
}
return d[t] != INF;
}
int slove()
{
int C = ,F = ;
while (SPFA(src,tag))
{
int a = INF;
for (int i = p[tag]; i != - ; i = p[edge[i].u]) a = min(a,edge[i].cap - edge[i].flow);
for (int i = p[tag]; i != -; i = p[edge[i].u])
{
edge[i].flow += a;
edge[i ^ ].flow -= a;
}
C += d[tag] * a;
F += a;
}
return C;
}
int main()
{
//freopen("sample.txt","r",stdin);
int kase = ;
while (scanf("%d%d",&P,&I) != EOF)
{
if (P == && I == ) break;
for (int i = ; i <= P; i++)scanf("%d",&nump[i]);
for (int i = ; i <= I; i++) scanf("%d",&numi[i]);
cnt = ;
memset(head ,- ,sizeof(head));
src = ;
tag = P + I + ;
for (int i = ;i <= P; i++)
for (int j = ; j <= I; j++)
{
double tmp;
scanf("%lf",&tmp);
if (tmp < - 0.5) G[i][j] = -;
else
{
tmp = (tmp * + 0.5);
G[i][j] = (int) tmp;
}
}
int retmin,retmax;
for (int i = ; i <= P; i++) addedge(src,i,nump[i],);
for (int i = ; i <= I; i++) addedge(P + i , tag ,numi[i],);
for (int i = ; i <= P; i++)
for (int j = ; j <= I; j++)
{
if (G[i][j] == -) continue;
addedge(i , P + j ,INF,G[i][j]);
}
retmin = slove();
cnt = ;
memset(head,-,sizeof(head));
for (int i = ; i <= P; i++) addedge(src,i,nump[i],);
for (int i = ; i <= I; i++) addedge(P + i , tag ,numi[i],);
for (int i = ; i <= P; i++)
for (int j = ; j <= I; j++)
{
if (G[i][j] == -) continue;
addedge(i , P + j ,INF,-G[i][j]);
}
retmax = - * slove();
printf("Problem %d: %.2lf to %.2lf\n",kase++,(double)retmin / 100.0,(double) retmax / 100.0);
}
return ;
}

UVALIVE 3562 Remember the A La Mode!的更多相关文章

  1. UVALive - 2965 Jurassic Remains (LA)

    Jurassic Remains Time Limit: 18000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Sub ...

  2. UVALive(LA) 4487 Exclusive-OR(带权并查集)

    题意:对于n个数X[0]~X[n-1],但你不知道它们的值,通过逐步提供给你的信息,你的任务是根据这些信息回答问题,有三种信息如下: I p  v : Xp = v;    Xp 的值为v I p q ...

  3. UVALive(LA) 3644 X-Plosives (并查集)

    题意: 有一些简单化合物,每个化合物都由两种元素组成的,你是一个装箱工人.从实验员那里按照顺序把一些简单化合物装到车上,但这里存在安全隐患:如果车上存在K个简单化合物,正好包含K种元素,那么他们就会组 ...

  4. leggere la nostra recensione del primo e del secondo

    La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...

  5. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  6. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  7. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  8. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  9. UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

随机推荐

  1. 为Zabbix配置RabbitMQ监控模板

    RabbitMQ的配置参考 https://github.com/jasonmcintosh/rabbitmq-zabbix 简而言之,具体分为几个步骤: 1. 将脚本文件(scripts文件夹)和配 ...

  2. 当我们在安装tensorflow时,我们在安装什么?- Intro to TF, Virtualenv, Docker, CUDA, cuDNN, NCCL, Bazel

    (Mainly quoted from its official website) Summary: 1. TensorFlow™ is an open source software library ...

  3. 传输控制层协议TCP概述---抄书

    1.TCP的主要特点 TCP是TCP/IP体系中非常复杂的一个协议.下面介绍TCP的最主要的特点. (1)TCP是面向连接的运输层协议.也就是说,应用程序在使用TCP协议之前,必须先建立TCP连接.在 ...

  4. Android Studio环境解读

    一.使用IDE开发APP的流程 要熟悉一个新的IDE,可依次完成以下流程: 二.相关术语解析 Dalvik: Android特有的虚拟机,和JVM不同,Dalvik虚拟机非常适合在移动终端上使用! A ...

  5. chromium源码阅读--图片处理

    JavaScript 图像替换 JavaScript 图像替换技术检查设备能力,然后“做正确的事”. 您可以通过 window.devicePixelRatio 确定设备像素比,获取屏幕的宽度和高度, ...

  6. Mybatis学习系列(六)延迟加载

    延迟加载其实就是将数据加载时机推迟,比如推迟嵌套查询的执行时机.在Mybatis中经常用到关联查询,但是并不是任何时候都需要立即返回关联查询结果.比如查询订单信息,并不一定需要及时返回订单对应的产品信 ...

  7. 基于Thinkphp5+phpQuery 网络爬虫抓取数据接口,统一输出接口数据api

    TP5_Splider 一个基于Thinkphp5+phpQuery 网络爬虫抓取数据接口 统一输出接口数据api.适合正在学习Vue,AngularJs框架学习 开发demo,需要接口并保证接口不跨 ...

  8. 匿名内存 | shm

    page_is_file_cache是和swapbacked互斥的,所以说对于匿名页来说,分配的时候就就会把PageSwapBacked给设置上,page->mapping_address = ...

  9. NOIP模板

    快排 procedure qsort(l,r:longint); var i,j,t,m:longint; begin i:=l; j:=r; m:=a[(i+j) ]; repeat while a ...

  10. ECharts饼图制作分析

    ECharts,缩写来自Enterprise Charts,商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9/10/11 ...