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 ...
随机推荐
- 第十六篇 Python之迭代器与生成器
一.迭代器 一. 递归和迭代 生活实例说明什么是递归和迭代 A想去腾达大厦,问B怎么走路,B 说我不知道,我给你问问C,C也不知道,C又去问D,D知道,把路告诉了C,C又告诉B,B最后告诉A, 这就是 ...
- ASP NET Core --- HTTP 翻页、过滤、排序
参照 草根专栏- ASP.NET Core + Ng6 实战:https://v.qq.com/x/page/v07647j3zkq.html 翻页, 过滤, 排序等 – 如何传递参数? Query ...
- ThinkPHP自定义成功界面、失败界面、异常界面
在ThinkPHP的手册中,附录里边的配置参考,有一个模板引擎设置. 或者在手册里面的控制器,跳转和重定向里面. 紧接着,就讲到了如何自定义这些界面. 将上诉的配置参数写到到配置文件里,修改路径到自己 ...
- BZOJ 1010 HNOI2008 玩具装箱 斜率优化
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1010 Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的 ...
- 软工实践 - 第二十七次作业 Beta 冲刺(5/7)
队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/10134471.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过 ...
- React & styled component
React & styled component https://www.styled-components.com/#your-first-styled-component tagged t ...
- jquery中ajax的使用(java)
AJAX方式 js:界面 var prjContextPath='<%=request.getContextPath()%>'; $(document).ready(function() ...
- IIS 发布后无法连接数据库(应用池问题)
查找网站对应的 应用池,修改为 .net4.0 然后设置启动32位应用程序为 True
- 2018牛客多校第一场 B.Symmetric Matrix
题意: 构造一个n*n的矩阵,使得Ai,i = 0,Ai,j = Aj,i,Ai,1+Ai,2+...+Ai,n = 2.求种类数. 题解: 把构造的矩阵当成邻接矩阵考虑. 那么所有点的度数都为2,且 ...
- C语言的getopt
By francis_hao Jul 5,2017 getopt:分析命令行选项 概述 #include <unistd.h>int getopt(int argc, char ...