POJ 3469 Dual Core CPU ——网络流
【题目分析】
构造一个最小割的模型。
S向每一个点连Ai,每一个点向T连Bi。
对于每一个限制条件,在i和j之间连一条Cij的双向边即可。
然后求出最小割就是最少的花费。
验证最小割的合理性很容易。
【代码】
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> //#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 50005
#define ll long long
#define me 400005
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i) void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int h[me<<1],to[me<<1],ne[me<<1],fl[me<<1],en=0,S=0,T=me-1; void add(int a,int b,int c)
{
to[en]=b; ne[en]=h[a]; fl[en]=c; h[a]=en++;
// to[en]=a; ne[en]=h[b]; fl[en]=0; h[b]=en++;
} int map[me]; bool tell()
{
queue <int> q;
memset(map,-1,sizeof map);
map[S]=0;
while (!q.empty()) q.pop();
q.push(S);
while (!q.empty())
{
int x=q.front(); q.pop();
for (int i=h[x];i>=0;i=ne[i])
{
if (map[to[i]]==-1&&fl[i]>0)
{
map[to[i]]=map[x]+1;
q.push(to[i]);
}
}
}
if (map[T]!=-1) return true;
return false;
} int zeng(int k,int r)
{
if (k==T) return r;
int ret=0;
for (int i=h[k];i>=0&&ret<r;i=ne[i])
if (map[to[i]]==map[k]+1&&fl[i]>0)
{
int tmp=zeng(to[i],min(fl[i],r-ret));
ret+=tmp; fl[i]-=tmp; fl[i^1]+=tmp;
}
if (!ret) map[k]=-1;
return ret;
} int main()
{
memset(h,-1,sizeof h);
Finout();
int n,m,a,b,c;
n=Getint();m=Getint();
F(i,1,n)
{
a=Getint(); b=Getint();
add(S,i,a);
add(i,S,0);
add(i,T,b);
add(T,i,0);
}
F(i,1,m)
{
a=Getint(); b=Getint();
c=Getint();
add(a,b,c);
add(b,a,c);
}
int ans=0,tmp;
while (tell()) while (tmp=zeng(S,inf)) ans+=tmp;
cout<<ans<<endl;
}
POJ 3469 Dual Core CPU ——网络流的更多相关文章
- POJ 3469.Dual Core CPU 最大流dinic算法模板
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 24830 Accepted: 10756 ...
- POJ 3469 Dual Core CPU Dual Core CPU
Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 23780 Accepted: 10338 Case Time Lim ...
- poj 3469 Dual Core CPU【求最小割容量】
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 21453 Accepted: 9297 ...
- 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题
[题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...
- poj 3469 Dual Core CPU——最小割
题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...
- POJ 3469 Dual Core CPU(最小割)
[题目链接] http://poj.org/problem?id=3469 [题目大意] 有N个模块要在A,B两台机器上执行,在不同机器上有不同的花费 另有M个模块组(a,b),如果a和b在同一台机子 ...
- 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中 ...
- poj 3469 Dual Core CPU 最小割
题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...
随机推荐
- Jquery AJAX使用踩坑小记
在使用jquery ajax时,如果其参数是一个json对象,将此参数使用$('#dd').data(param)绑定到一个元素上, 在使用$('#dd').bind('click',function ...
- uvm_driver——老司机带带我
文件:src/comps/uvm_driver.svh类: uvm_driver uvm_driver继承(C++中叫继承)自uvm_component,其中定义了两个Ports:seq_item_p ...
- sql中的exsits和not exsits
select * from table where exsits(sql语句) : 括号中sql语句有数据则返回这些相关id的数据集 select * from table where not ex ...
- Windows Server 2008 R2中上传和下载文件
在 Windows Server 2008 R2 中,使用服务器管理器来启用或禁用 Windows 功能,那在这个上面如何上传和下载文件呢? 1.在“服务器管理器”->“角色”->“web ...
- leetcode_1095. Find in Mountain Array_[Binary Search]
https://leetcode.com/problems/find-in-mountain-array/ 题意:给定一个MountainArray(定义见题目),找到其中最早出现的target值的下 ...
- Vue 打印预览功能
需求有几种情况: 1.直接在HTML写页面,将页面上的东西用A4纸打印出来: 2.后台传回PDF文件,前台浏览器预览并打印: 3.后台做好要打印的,传回图片,如base64编码,前台浏览器 预览并打印 ...
- stringstream类的简介和用法
一.简介 <sstream>类库定义了三种类:istringstream,ostringstream,stringstream.分别用来进行流的输入,流的输出,输入输出操作.在此演示str ...
- hibernate4整合spring3.1的过程中的异常问题
(1)hibernate4整合spring3.1的过程中,发现了java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider异常 ...
- bootstrap下拉菜单(Dropdowns)
本章将重点讲解bootstrap下拉菜单(Dropdowns),下拉菜单是可切换的,是以列表格式显示链接的上下文菜单. <!DOCTYPE html><html><hea ...
- springboot 修炼之路
网上无意中发现一份关于springboot的教程说明,说的很详细,大家可以参考.具体地址:http://www.spring4all.com/article/246