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 ...
随机推荐
- SQL Sever 2008 R2版本添加Northwin数据库错误解决
一.环境: OS: Windows 7 ProfessionalSQL Server 2008 R2 二.示例数据库Northwind下载(mdf) Northwind 三.附加数据库: 打开Micr ...
- Python:数据可视化pyecharts的使用
什么是pyecharts? pyecharts 是一个用于生成 Echarts 图表的类库. echarts 是百度开源的一个数据可视化 JS 库,主要用于数据可视化.pyecharts 是一个用于生 ...
- Struts2与Spring整合
前言 本博文主要讲解Spring怎么与Struts2框架整合... Struts2和Spring的整合关键点: action对象交给Spring来创建 搭建环境 进入jar包 引入jar文件: 1)引 ...
- Centos7-yum部署配置LNMP+php-fgm,一台机器上部署
一.简介 1.了解nginx特性 请参考,https://www.cnblogs.com/zhangxingeng/p/10150955.html 2.LNMP:linux+nginx+mysql+p ...
- 【.NET Core项目实战-统一认证平台】第十六章 网关篇-Ocelot集成RPC服务
[.NET Core项目实战-统一认证平台]开篇及目录索引 一.什么是RPC RPC是"远程调用(Remote Procedure Call)"的一个名称的缩写,并不是任何规范化的 ...
- MySQL 8.0版本连接报错:Could not create connection to database server.
准备搭建一个Spring Boot 组合mybatis的项目,数据库采用的是MySQL 8.0.11按照以往的配置,使用插件mybatis-generator-maven-plugin生成代码时,一直 ...
- [MySQL]select和where子句优化
数据库优化:1.可以在单个SQL语句,整个应用程序,单个数据库服务器或多个联网数据库服务器的级别进行优化2.数据库性能取决于数据库级别的几个因素,例如表,查询和配置设置3.在数据库级别进行优化,在硬件 ...
- Php中的goto用法
我们先举个简单示例: <?php goto LABEL; //这个标签自定义 echo '乔峰'; LABEL: echo '鸠摩智'; 以上例程会输出:鸠摩智 解释:goto 操作符可以用来跳 ...
- netfilter及iptables基本概念
网络访问控制 网络访问控制可以简单理解为防火墙,常用的网络访问控制有:哪些IP可以访问服务器, 可以使用哪些协议,哪些接口,是否需要对数据包进行修改等. netfilter netfilter是通过i ...
- C#设计模式之二十二备忘录模式(Memento Pattern)【行为型】
一.引言 今天我们开始讲“行为型”设计模式的第十个模式,该模式是[备忘录模式],英文名称是:Memento Pattern.按老规矩,先从名称上来看看这个模式,个人的最初理解就是对某个对象的状态进行保 ...