题意:

N个模块可以在A,B两个核上运行,分别需要A[i]和B[i],模块之间需要传递数据,若两个模块在同一核上,则不需要花费,否则需要花费w[i]。问最少需要花费多少?

分析:

用最小的费用将两个对象分成两个集合的问题,常常可以转换为最小割问题。

按照N个模块在哪个核上运行分成两个集合。并建边使最小费用等于最小割的容量,即转化为求图中最大流。

代码:

#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
struct edge{int to, cap, rev;};
const int maxm = 20010, INF = 0x3fffffff;
int d[maxm], iter[maxm];
int s, t;
vector<edge>G[maxm];
void add_edge(int from, int to, int cap)
{
G[from].push_back((edge){to, cap, G[to].size()});
G[to].push_back((edge){from, 0, G[from].size()-1});
}
void bfs()
{
memset(d, -1, sizeof(d));
queue<int>q;
d[s] = 0;
q.push(s);
while(!q.empty()){
int v = q.front();q.pop();
for(int i = 0; i <G[v].size(); i++){
edge &e = G[v][i];
if(e.cap>0&&d[e.to]<0){
d[e.to] = d[v] + 1;
q.push(e.to);
}
}
}
}
int dfs(int v, int f)
{
if(v==t) return f;
for(int &i = iter[v]; i < G[v].size(); i++){
edge &e = G[v][i];
if(e.cap > 0 && d[v] < d[e.to]){
int tf = dfs(e.to, min(f, e.cap));
if(tf > 0){
e.cap -= tf;
G[e.to][e.rev].cap +=tf;
return tf;
}
}
}
return 0;
}
int max_flow()
{
int flow = 0;
for(;;){
bfs();
if(d[t]<0) return flow;
memset(iter, 0, sizeof(iter));
int f;
while((f = dfs(s, INF))>0){
flow += f;
}
}
}
int main (void)
{
int N, M;scanf("%d%d",&N,&M);
s = N + 1, t = s +1;
int A, B;
for(int i = 1; i <= N;i++){
scanf("%d%d",&A,&B);
add_edge(s, i, B);
add_edge(i, t, A);
}
int a, b, w;
for(int i = 0; i < M; i++){
scanf("%d%d%d",&a, &b, &w);
add_edge(a, b, w);
add_edge(b, a, w);
}
printf("%d\n",max_flow());
}

输入时少读个数都能过样例。也是奇葩【手动再见】。还是细心细心。

POJ 3469_Dual Core CPU的更多相关文章

  1. POJ 3469.Dual Core CPU 最大流dinic算法模板

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 24830   Accepted: 10756 ...

  2. POJ 3469 Dual Core CPU Dual Core CPU

    Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 23780   Accepted: 10338 Case Time Lim ...

  3. poj 3469 Dual Core CPU【求最小割容量】

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 21453   Accepted: 9297 ...

  4. Dual Core CPU

    Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 20935 Accepted: 9054 Case ...

  5. 2018.06.27Dual Core CPU(最小割)

    Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 26136 Accepted: 11270 Cas ...

  6. poj3469 Dual Core CPU

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 25576   Accepted: 11033 ...

  7. Inter Core CPU 型号的尾字母含义

    Inter Core CPU 型号的尾字母含义: M:表示移动处理器(Mobile Processor):QM:四核移动处理器(Quad Mobile Processor):U:超低电压处理器(Ult ...

  8. POJ 3469 Dual Core CPU (最小割建模)

    题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...

  9. poj 3469 Dual Core CPU

    题目描述:由于越来越多的计算机配置了双核CPU,TinySoft公司的首席技术官员,SetagLilb,决定升级他们的产品-SWODNIW.SWODNIW包含了N个模块,每个模块必须运行在某个CPU中 ...

随机推荐

  1. 使用 ServerSocket 进行文件上传,以及用Tomcat启动ServerSocket时,会卡死解决

    服务器端代码 import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.IOExcept ...

  2. [Luogu1345][USACO5.4]Telecowmunication 最大流

    题目链接:https://www.luogu.org/problem/show?pid=1345 求最小割点集的大小,直接拆点转化成最小割边.把一个点拆成出点入点,入点向出点连一条容量为1的边,其他的 ...

  3. R Programming week1-Subsetting

    Subsetting There are a number of operators that can be used to extract subsets of R objects. [ alway ...

  4. linux下svn安装(ALI ECS)

    yum安装svn 搭建和使用SVN 可参考阿里云文档:https://help.aliyun.com/document_detail/52864.html?spm=5176.8208715.110.1 ...

  5. WebAPI中Area的使用

    很简单,创建area后,添加一下代码到AreaRegistration中即可 context.Routes.MapHttpRoute( name: "api_default", r ...

  6. (二)Redis for 阿里云公网连接

    目录 (一)Redis for Windows正确打开方式 (二)Redis for 阿里云公网连接 (三)Redis for StackExchange.Redis 阿里云目前仅支持内网连接Redi ...

  7. zabbix监控之grafana

    zabbix监控之grafana

  8. VS2017 ATL创建ActiveX编程要点

    VS2017 ATL创建ActiveX控件编程要点: 一.创建vs项目需要安装器visual studio installer中: 安装 visual studio扩展开发中的 用于x86和x64的V ...

  9. 单文件组件.vue---父子组件通信

    每一个.vue 文件就是一个 组件,组件和组件相互组合,就成了一个应用,这就涉及到的组件和组件之间的通信,最常用的就是父子之间的通信.在vue 中, 在一个组件中通过 import 引入另一个组件,这 ...

  10. baidu让用户更快看到首页

    //让用户更快看到首页 if(!location.hash.match(/[^a-zA-Z0-9]wd=/)) { document.getElementById("wrapper" ...