POJ3686 The Windy's
嘟嘟嘟
刚做费用流,思路完全不对呀……
应该这么想(应该说敢这么想):这道题的关键在于怎么体现这个玩具是第几个加工的,只有这才能求出他的加工时间(因为加工时间包括等待时间)。
但等待时间不好求,因此要换个思路想:加工这个玩具会对别的玩具的加工时间造成多少影响。
假设三个玩具\(i, j, k\)依次在同一个工厂中被加工出来,那么总时间\(T = t_i + (t_i + t_j) + (t_i + t_j + t_k) = 3 * t_i + 2 * t_j + t_k\)。所以一个玩具对总时间的贡献是:加工次序\(*\)制作时间。
那么建图就有思路了:把每一个工厂拆成\(n\)个点,代表加工次序。对于每一个玩具\(i\),向每一个工厂\(j\)的每一个加工次序的点\(k\)连一条容量为1,费用为\(k * cost_{i, j}\)的边。然后从源点向玩具连边,从每一个拆开的的工厂向汇点连边。
跑费用流。
最后要提醒的是算好空间。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int N = 50;
const int maxn = N + N * N + 5;
const int maxe = N + N * N + N * N * N + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n, m, s, t, a[N + 5][N + 5];
struct Edge
{
int nxt, from, to, cap, c;
}e[maxe << 1];
int head[maxn], ecnt = -1;
void addEdge(int x, int y, int w, int c)
{
e[++ecnt] = (Edge){head[x], x, y, w, c};
head[x] = ecnt;
e[++ecnt] = (Edge){head[y], y, x, 0, -c};
head[y] = ecnt;
}
bool in[maxn];
int dis[maxn], pre[maxn], flow[maxn];
bool spfa()
{
Mem(in, 0); Mem(dis, 0x3f);
in[s] = 1; dis[s] = 0; flow[s] = INF;
queue<int> q; q.push(s);
while(!q.empty())
{
int now = q.front(); q.pop(); in[now] = 0;
for(int i = head[now], v; i != -1; i = e[i].nxt)
{
v = e[i].to;
if(e[i].cap > 0 && dis[now] + e[i].c < dis[v])
{
dis[v] = dis[now] + e[i].c;
pre[v] = i;
flow[v] = min(flow[now], e[i].cap);
if(!in[v]) in[v] = 1, q.push(v);
}
}
}
return dis[t] != INF;
}
int minCost = 0;
void update()
{
int x = t;
while(x != s)
{
int i = pre[x];
e[i].cap -= flow[t];
e[i ^ 1].cap += flow[t];
x = e[i].from;
}
minCost += flow[t] * dis[t];
}
void MCMF()
{
while(spfa()) update();
}
int main()
{
int T = read();
while(T--)
{
Mem(head, -1); ecnt = -1; minCost = 0;
n = read(); m = read(); s = 0, t = n + n * m + 1;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j) a[i][j] = read();
for(int i = 1; i <= n; ++i)
{
addEdge(s, i, 1, 0);
for(int j = 1; j <= m; ++j)
for(int k = 1; k <= n; ++k)
addEdge(i, j * n + k, 1, k * a[i][j]);
}
for(int i = n + 1; i <= n * m + n; ++i) addEdge(i, t, 1, 0);
MCMF();
printf("%.6f\n", (db)minCost / (db)n);
}
return 0;
}
POJ3686 The Windy's的更多相关文章
- POJ3686 The Windy's 【费用流】*
POJ3686 The Windy’s Description The Windy’s is a world famous toy factory that owns M top-class work ...
- POJ-3686 The Windy's KM算法 拆点题
参考:https://blog.csdn.net/sr_19930829/article/details/40680053 题意: 有n个订单,m个工厂,第i个订单在第j个工厂生产的时间为t[i][j ...
- POJ3686 The Windy's(最小费用最大流)
题目大概说要用m个工厂生产n个玩具,第i个玩具在第j个工厂生产要Zij的时间,一个工厂同一时间只能生成一个玩具,问最少的用时. 这题建的图不是很直观.. 源点向玩具连容量1费用0的边 将每个工厂拆成n ...
- [poj3686]The Windy's(费用流)
题目大意: 解题关键:指派问题,待更. #include<cstdio> #include<cstring> #include<algorithm> #includ ...
- POJ3686:The Windy's——题解
http://poj.org/problem?id=3686 题目大意: 有n个订单m个厂子,第i个订单在第j个厂子所需时间为zij,一个厂子做一个订单时不能做其他的订单. 求订单平均时间最小值. — ...
- BZOJ1026: [SCOI2009]windy数[数位DP]
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 6346 Solved: 2831[Submit][Sta ...
- BZOJ1026: [SCOI2009]windy数
传送门 md直接wa了78次,身败名裂 没学过数位DP硬搞了一道数位DP的模板题,感觉非常的愉(sha)悦(cha). 二分转化枚举思想.首先DP预处理出来$f[i][j]$表示有$i$位且第$i$位 ...
- jQuery jquery.windy 快速浏览内容
在线实例 效果一 效果二 效果三 使用方法 <div class="container"> <section class="main" ...
- BZOJ 1026 【SCOI2009】 windy数
Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数? I ...
随机推荐
- 使用mpvue开发小程序教程(四)
在上一章节中,我们将vue-cli命令行工具生成的代码骨架中的src目录清理了一遍,然后从头开始配置和编写了一个可以运行的小程序页面,算是正真走上了使用mpvue开发小程序的第一步.今天我们将进一步来 ...
- 聚类——FCM
聚类——认识FCM算法 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 一.FCM概述 FCM算法是基于对目标函数的优化基础上的一种数据聚类方法.聚类结 ...
- ppt制作元素采集
原文链接 https://www.zhihu.com/question/52157612/answer/247501754?utm_source=qq&utm_medium=social 1动 ...
- MVC基本开发介绍 (1)列表展示
前言: 现在如果用.net 的解决方案来做网站或者是网站的后台管理系统,MVC 应该是比较流行的. 自从进了新公司后,也一直在用mvc + webapi 来做项目,这里做个分享性的总结,有更好的方法欢 ...
- 巨杉数据库加入CNCF云原生应用计算基金会,共建开源技术生态
近日,巨杉数据库正式加入全球顶级开源社区,云原生应用计算基金会 (Cloud Native Computing Foundation,以下简称CNCF),成为CNCF基金会会员,是中国最早加入的开源云 ...
- shell编程练习(二): 笔试11-20
笔试练习(二): 11.写一个shell脚本来得到当前的日期,时间,用户名和当前工作目录. [root@VM_0_5_centos test]# vi 11.sh [root@VM_0_5_cento ...
- 【.NET Core项目实战-统一认证平台】第九章 授权篇-使用Dapper持久化IdentityServer4
[.NET Core项目实战-统一认证平台]开篇及目录索引 上篇文章介绍了IdentityServer4的源码分析的内容,让我们知道了IdentityServer4的一些运行原理,这篇将介绍如何使用d ...
- mybatis_16逆向工程
简介 简单点说,就是通过数据库中的单表,自动生成java代码. Mybatis官方提供了逆向工程 可以针对单表自动生成mybatis代码(mapper.java\mapper.xml\po类) 企业开 ...
- 让Mongo在Spring中跑起来
本文标题为<让Mongo在Spring中跑起来>,旨在Spring中如何成功连接MongoDB并对其进行增删改查等操作,由于笔者也是刚接触,对其中的一些原由也不甚了解,若有错误之处,敬请指 ...
- 微信公众平台设置URL和Token接收接口事件推送
最近做对接微信闪开发票-微信发票名片,里面有个接收用户提交抬头接口是微信推送事件到公众号后台,该事件将发送至开发者填写的URL(登录公众平台进入[开发者中心设置]). 开发者可通过事件推送完成数据统计 ...