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

#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. JVM 什么时候会触发FGC

    1:System.gc(); 2:老年代满了 没啥好说的从年轻代去往老年代的 3:JDK7或JDK6中永久区满了 得看是否还会有分配,如果没有就不会进行FGC,不过CMS GC下会看到不停地CMS G ...

  2. 九度OJ--Q1163

    import java.util.ArrayList;import java.util.Scanner; /* * 题目描述: * 输入一个整数n(2<=n<=10000),要求输出所有从 ...

  3. win10激活方法-专业版

    该教程操作思路,Win10家庭版升为专业版,然后激活版本 首先,进入设置→关于看到如下页面: 接着,进入实操阶段: 第一步   在激活版面输入密匙   ( 把家庭版升级为专业版 ) DR9VN-GF3 ...

  4. TensorFlow 常见错误与解决方法——长期不定时更新

    1. TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a builtin_function_or_method ...

  5. mongolass 中报 ($.content: "say Hi ~") ✖ (type: String)

    第二次报这个错了, 一直以为MongoDB的模型用的type 是 String, 一直报错, 找不到原因. // 留言模型1 exports.Comment = mongolass.model('Co ...

  6. SQLAlchemy 学习笔记(二):ORM

    照例先看层次图 一.声明映射关系 使用 ORM 时,我们首先需要定义要操作的表(通过 Table),然后再定义该表对应的 Python class,并声明两者之间的映射关系(通过 Mapper). 方 ...

  7. [leetcode-646-Maximum Length of Pair Chain]

    You are given n pairs of numbers. In every pair, the first number is always smaller than the second ...

  8. POJ 2186 Popular Cows(强联通+缩点)

    Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...

  9. Uva 1590 IP Networks

    这道题目是一道关于IP地址的题目,要深入理解这道题需要有一定的网络基础. 这道题目我第一次做的时候虽然也AC了,但代码写的比较复杂,不够精炼.近期刚刚参加了网络方面的培训,在有一定知识的基础上,又重写 ...

  10. 用vs调试项目页面无样式

    ASP.NET Development Server 上的文件授权 在文件系统网站中,静态文件(例如图像和样式表)遵守 ASP.NET 授权.例如,如果禁用了对静态文件的匿名访问,匿名用户则不能使用文 ...