UVALIVE 3562 Remember the A La Mode!
费用流 建图很简单直接上代码
#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!的更多相关文章
- UVALive - 2965 Jurassic Remains (LA)
Jurassic Remains Time Limit: 18000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Sub ...
- UVALive(LA) 4487 Exclusive-OR(带权并查集)
题意:对于n个数X[0]~X[n-1],但你不知道它们的值,通过逐步提供给你的信息,你的任务是根据这些信息回答问题,有三种信息如下: I p v : Xp = v; Xp 的值为v I p q ...
- UVALive(LA) 3644 X-Plosives (并查集)
题意: 有一些简单化合物,每个化合物都由两种元素组成的,你是一个装箱工人.从实验员那里按照顺序把一些简单化合物装到车上,但这里存在安全隐患:如果车上存在K个简单化合物,正好包含K种元素,那么他们就会组 ...
- 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 ...
- 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 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 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 ...
随机推荐
- coia阻止事件上浮
1.阻止事件上浮 选择默认地址li 时 选中整个div使其为默认地址 此时点击编辑按钮也会触发选中默认事件 为事件添加event.stopPropagation();阻止事件上浮 2.js给页面inp ...
- MySql数据库插入或更新报错:Cannot add or update a child row: a foreign key constraint fails
具体报错信息: Cannot add or update a child row: a foreign key constraint fails (`xxx`.`AAA`, CONSTRAINT `t ...
- Python中enumerate函数用法详解
enumerate函数用于遍历序列中的元素以及它们的下标,多用于在for循环中得到计数,enumerate参数为可遍历的变量,如 字符串,列表等 一般情况下对一个列表或数组既要遍历索引又要遍历元素时, ...
- 【翻译】ASP.NET Core 文档目录
微软官方CORE 2.0正式版中文文档已经出来了,地址:https://docs.microsoft.com/zh-cn/aspnet/core/ 简介 入门 创建一个Web应用程序 创建一个Web ...
- STL中的set容器的一点总结2
http://blog.csdn.net/sunshinewave/article/details/8068326 1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像 ...
- LTE QCI分类 QoS
http://blog.163.com/gzf_lte/blog/static/20840310620130140057204/ http://blog.163.com/gzf_lte/blog/st ...
- Delphi GetCurrentDir 获取当前文件夹
//获取当前文件夹 GetCurrentDirvardir: string;begindir := GetCurrentDir;ShowMessage(dir); //C:\Documents and ...
- [NOIP2016]愤怒的小鸟 DP
---题面--- 题解: 首先观察数据范围,n <= 18,很明显是状压DP.所以设f[i]表示状态为i时的最小代价.然后考虑转移. 注意到出发点(0, 0)已经被固定,因此只需要2点就可以确定 ...
- BZOJ 2502: 清理雪道 | 有上下界最小流
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> #defi ...
- C++——拷贝构造函数说明
一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: [c-sharp] view plaincopy 1 int a = 100; 2 int b = a; 而类对 ...