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 ...
随机推荐
- 剑指offer-用两个栈实现队列05
class Solution: def __init__(self): self.stackpush=[] self.stackpop=[] def push(self, node): # write ...
- 基于eth快速发行自己的数字货币
我们总在寻觅,也不断迷失. 像一颗飘摇的韭菜,彷徨而又无奈,无奈又彷徨. 如果你问我未来,我不知去向何方 我只知道生长,恣意野蛮. 我们不断在追寻一款爆款的项目,一个百倍币千倍币,却没有想到,实际上做 ...
- vue里的this
vue中methods对象里的函数, this指向的都是当前实例或者组件.
- 每个分组函数相当于一个for循环 将集合的变量不断遍历
每个分组函数相当于一个for循环 将集合的变量不断遍历
- 【bzoj1878】[SDOI2009]HH的项链 树状数组
题目描述 HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH不断地收集新的贝壳,因此, 他的项链变得越来越长.有一 ...
- Codeforces 662C(快速沃尔什变换 FWT)
感觉快速沃尔什变换和快速傅里叶变换有很大的区别啊orz 不是很明白为什么位运算也可以叫做卷积(或许不应该叫卷积吧) 我是看 http://blog.csdn.net/liangzhaoyang1/ar ...
- 种树 by yoyoball [树分块+bitset]
题面 给定一棵树,有点权 每次询问给出一些点对,求这些点对之间的路径的并集上不同权值的个数,以及这些权值的$mex$ 思路 先考虑只有一对点对,只询问不同权值个数的问题:树上莫队模板题 然后加个$me ...
- MySQL自增属性auto_increment_increment和auto_increment_offset
MySQL的系统变量或会话变量auto_increment_increment(自增步长)和auto_increment_offset(自增偏移量)控制着数据表的自增列ID. mysql> sh ...
- visio应用程序相关设置-选项-视图
1.是否显示"新建"选项卡,可读/写 ApplicationSettings.ShowChooseDrawingTypePane m_Visio.Window.Applicatio ...
- BZOJ2120 数颜色 【带修改莫队】
2120: 数颜色 Time Limit: 6 Sec Memory Limit: 259 MB Submit: 6579 Solved: 2625 [Submit][Status][Discus ...