POJ3469Dual Core CPU
题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费。
分析: 用最小的费用将对象划分成两个集合的问题,常常可以转化成最小割后解决,这题就是一道经典的问题;
1.考虑把N个模块按照在那个核执行分成两个集合。在A执行为集合S,B为T。
2.当模块属于A集的时候,花费为ai,所以就从向t连一条ai的边,而当模块属于B集的时候,花费为bi,所以就由s连一条向bi的边。然后对于每个任务,当ai,bi不同的时候花费为mi,所以就由ai,bi连两条容量为wi的边,跑一下最大流就可以得出对应的最小花费了
3.为什么会想到这些呢?首先来了解下:最小割,就是在流向图上去掉数量最少容量最小的边,使这个图变得不连通,源点s无法到达汇点t,这些边组成的容量就是最小割。那我们是不是可以想到,与最小费用进行对比,如果我们建的图是满足最小割为答案的话,那我们就可以很容易解决问题了;
4. 大佬文献
代码:
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#define ll long long
#define maxn 23500
#define maxe 1000000
#define inf 1100000000
using namespace std; struct Edge
{
int u, v, cap;
int nxt;
}edge[maxe]; int head[maxn];
int n, m; struct Dicnic
{
int level[maxn];
int iter[maxn];
int add;
void init(){
add = ; memset(head, -, sizeof(head));
memset(iter, -, sizeof(iter));
}
void insert(int u, int v, int c){
edge[add].u = u; edge[add].v = v; edge[add].cap = c;
edge[add].nxt = head[u]; head[u] = add++;
edge[add].u = v; edge[add].v = u; edge[add].cap = ;
edge[add].nxt = head[v]; head[v] = add++;
}
void bfs(int s){
memset(level, -, sizeof(level));
queue<int> que;
level[s] = ;
que.push(s);
while (!que.empty()){
int v = que.front(); que.pop();
for (int i = head[v]; i != -; i = edge[i].nxt){
Edge &e = edge[i];
if (e.cap > && level[e.v] < ){
level[e.v] = level[v] + ;
que.push(e.v);
}
}
}
} int dfs(int v, int t, int f){
if (v == t) return f;
for (int &i = iter[v]; i != -; i = edge[i].nxt){
Edge &e = edge[i]; Edge &reve = edge[i ^ ];
if (e.cap > && level[v] < level[e.v]){
int d = dfs(e.v, t, min(f, e.cap));
if (d>){
e.cap -= d; reve.cap += d;
return d;
}
}
}
return ;
} int max_flow(int s, int t){
int flow = ;
for (;;){
bfs(s);
if (level[t] < ) return flow;
memcpy(iter, head, sizeof(iter));
int f;
while ((f = dfs(s, t, inf))>){
flow += f;
}
}
}
}net; int a[maxn], b[maxn]; int main()
{
while (cin >> n >> m){
net.init();
int s = , t = n + ;
for (int i = ; i <= n; i++) {
scanf("%d", a + i); scanf("%d", b + i);
net.insert(i, t, a[i]);
net.insert(s, i, b[i]);
}
int ui, vi, wi;
for (int i = ; i < m; i++){
scanf("%d%d%d", &ui, &vi, &wi);
net.insert(ui, vi, wi);
net.insert(vi, ui, wi);
}
printf("%d\n", net.max_flow(s,t));
}
return ;
}
POJ3469Dual Core CPU的更多相关文章
- Inter Core CPU 型号的尾字母含义
Inter Core CPU 型号的尾字母含义: M:表示移动处理器(Mobile Processor):QM:四核移动处理器(Quad Mobile Processor):U:超低电压处理器(Ult ...
- Dual Core CPU
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 20935 Accepted: 9054 Case ...
- poj 3469 Dual Core CPU【求最小割容量】
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 21453 Accepted: 9297 ...
- POJ 3469.Dual Core CPU 最大流dinic算法模板
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 24830 Accepted: 10756 ...
- 2018.06.27Dual Core CPU(最小割)
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 26136 Accepted: 11270 Cas ...
- POJ 3469 Dual Core CPU Dual Core CPU
Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 23780 Accepted: 10338 Case Time Lim ...
- poj3469 Dual Core CPU
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 25576 Accepted: 11033 ...
- POJ 3469 Dual Core CPU (最小割建模)
题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...
- poj 3469 Dual Core CPU
题目描述:由于越来越多的计算机配置了双核CPU,TinySoft公司的首席技术官员,SetagLilb,决定升级他们的产品-SWODNIW.SWODNIW包含了N个模块,每个模块必须运行在某个CPU中 ...
随机推荐
- java连接字符串操作,可用来向sql传值
private static String concat(String tag,String Time) { // TODO Auto-generated method stub // return ...
- jstl 判断 null
<c:if test="${not empty object }"> ${object}不为空 </c:if>
- python爬虫(10)--PyQuery的用法
简介 pyquery 可让你用 jQuery 的语法来对 xml 进行操作.这I和 jQuery 十分类似.如果利用 lxml,pyquery 对 xml 和 html 的处理将更快. 初始化 在这里 ...
- jetty分析
jetty处理过程: 1 new Server() (1)初试化线程池 生成固定大小线程数,新来的线程放入BlockingQueue. (2)初始化ServerConnector 初始化 sche ...
- array_unique() 函数移除数组中的重复的值
array_unique() 函数移除数组中的重复的值,并返回结果数组. 当几个数组元素的值相等时,只保留第一个元素,其他的元素被删除. 返回的数组中键名不变.
- MSScriptControl详解(可实现在C#等语言中调用JAVASCRIPT代码)
ScriptControl接口 属性名称 类型 备注 AllowUI BOOL 检测是否允许运行用户的接口元素.如果为False,则诸如消息框之类的界面元素不可见. CodeObject Object ...
- 业务逻辑:shiro框架的功能实现
思路:分别在web.xml配置过滤器以及在applicationContext.xml去配置 实现步骤:1.在pom.xml里引入shiro的坐标 2.在web.xml里配置shiro过滤器 3.在a ...
- QGraphicsScene绘制网格背景
博客转载自:https://blog.csdn.net/u010177010/article/details/51496038 //两条轴线QPolygonF myPolygon1; myPolygo ...
- ZROI2018普转提day1t4
传送门 分析 就是飞飞侠这道题...... 我们可以将这张图建成好几层,每一层可以向下一层的上下左右无代价移动,而对于每个点如果付b[i][j]的代价就可以走到比它高a[i][j]的层上.我们用这种方 ...
- 操作系统 Linux ex2 note
locate filename 搜索文件 将当前用户目录下的文件清单输出到文件list1.txt(当前用户目录下)中.ls -l > list1.txt 利用管道命令将根(/)下所有修改日期在4 ...