BZOJ3511: 土地划分
【传送门:BZOJ3511】
简要题意:
给出n个点,m条边,每个点有A和B两种形态,一开始1为A,n为B
给出VA[i]和VB[i],表示第i个点选择A和B形态的价值
每条边给出x,y,EA,EB,EC,表示如果x和y都为A,则获得EA价值,如果都为B则获得EB价值,否则会得到EC的费用(就是负价值)
求出最大价值
题解:
神奇的最小割,太强了
参考代码:
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- struct node
- {
- int x,y,c,next,other;
- }a[];int len,last[];
- void ins(int x,int y,int c)
- {
- int k1=++len,k2=++len;
- a[k1].x=x;a[k1].y=y;a[k1].c=c;
- a[k1].next=last[x];last[x]=k1;
- a[k2].x=y;a[k2].y=x;a[k2].c=;
- a[k2].next=last[y];last[y]=k2;
- a[k1].other=k2;
- a[k2].other=k1;
- }
- int h[],list[],st,ed;
- bool bt_h()
- {
- memset(h,,sizeof(h));
- h[st]=;
- int head=,tail=;
- list[]=st;
- while(head!=tail)
- {
- int x=list[head];
- for(int k=last[x];k;k=a[k].next)
- {
- int y=a[k].y;
- if(h[y]==&&a[k].c>)
- {
- h[y]=h[x]+;
- list[tail++]=y;
- }
- }
- head++;
- }
- if(h[ed]==) return false;
- else return true;
- }
- int findflow(int x,int f)
- {
- if(x==ed) return f;
- int s=,t;
- for(int k=last[x];k;k=a[k].next)
- {
- int y=a[k].y;
- if(h[y]==(h[x]+)&&a[k].c>&&f>s)
- {
- t=findflow(y,min(a[k].c,f-s));
- s+=t;
- a[k].c-=t;a[a[k].other].c+=t;
- }
- }
- if(s==) h[x]=;
- return s;
- }
- int main()
- {
- int n,m;
- scanf("%d%d",&n,&m);
- int sum=;st=;ed=n+*m+;
- len=;memset(last,,sizeof(last));
- ins(st,,);
- for(int i=;i<n;i++)
- {
- int d;
- scanf("%d",&d);sum+=d;
- ins(st,i,d);
- }
- ins(n,ed,);
- for(int i=;i<n;i++)
- {
- int d;
- scanf("%d",&d);sum+=d;
- ins(i,ed,d);
- }
- for(int i=;i<=m;i++)
- {
- int x,y,ea,eb,ec;
- scanf("%d%d%d%d%d",&x,&y,&ea,&eb,&ec);sum+=ea+eb;
- ins(x,y,ec);ins(y,x,ec);
- ins(i+n,x,);ins(i+n,y,);
- ins(x,i+n+m,);ins(y,i+n+m,);
- ins(st,i+n,ea);ins(i+n+m,ed,eb);
- }
- while(bt_h()==true) sum-=findflow(st,);
- printf("%d\n",sum);
- return ;
- }
BZOJ3511: 土地划分的更多相关文章
- BZOJ3511: 土地划分(最小割)
Description Y国有N座城市,并且有M条双向公路将这些城市连接起来,并且任意两个城市至少有一条路径可以互达. Y国的国王去世之后,他的两个儿子A和B都想成为新的国王,但他们都想让这个国家更加 ...
- fzu 1015 土地划分(判断线段相交+求出交点+找规律)
链接:http://acm.fzu.edu.cn/problem.php?pid=1015 Problem 1015 土地划分 Accept: 714 Submit: 1675Time Lim ...
- FOJ Problem 1015 土地划分
Problem 1015 土地划分 Accept: 823 Submit: 1956Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- BZOJ 3511 土地划分
AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3511 题目分析: 看上去和前面的人员雇佣以及小M种田都很像. 最小割模型来求最大值,一般都 ...
- FZU 1015 土地划分
Description 在Dukeswood这块土地上生活着一个富有的农庄主和他的几个孩子.在他临终时,他想把他的土地分给他的孩子.他有许多农场,每个农场都是一块矩形土地.他在农场地图上划上一 ...
- UVa1515 Pool construction(最小割)
题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【noip模拟赛3】拣钱
描述 最近,Henry由于失恋(被某大牛甩掉!)心情很是郁闷.所以,他去了大牛家,寻求Michael大牛的帮助,让他尽快从失恋的痛苦中解脱出来.Michael大牛知道Henry是很爱钱的,所以他是费尽 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- (DFS)HDU_1241 Oil Deposits
HDU_1241 Oil Deposits Problem Description The GeoSurvComp geologic survey company is responsible f ...
随机推荐
- SASS 使用(vs code)
二.在vs code中编译sass 1.在拓展商店里搜索“easy sass”,并安装,安装成功后点重新加载. 2.接下来进行配置: 在 vs code 菜单栏依次点击“文件 首选项 设置”,打开 s ...
- element-ui的table表格控件表头与内容列不对齐问题
原文链接:点我 element-ui的table表格控件表头与内容列不对齐问题 解决方法:将以下样式代码添加到index.html.或app.vue中(必须是入口文件,起全局作用!)body .el- ...
- 平凡主丛上的Yang-Mills理论
本文是复旦大学由丁青教授的暑期课程“Yang-Mills理论的几何及其应用”所作笔记,会有少许修正. 所需基础: 多元微积分学 微分方程(常微分方程,数学物理方程) 曲线曲面论(初等微分几何) 以下是 ...
- c++ string类的完整实现!!!
本文实现了c++ STL中的basic_string模板类,当然.通过typedef也就实现了string类和wstring类.限于篇幅,实现代码中用到了标准库的char_traits模板类,本人自己 ...
- Android面试题目整理与解说(一)
这一篇文章专门整理一下研究过的Android面试题,内容会随着学习不断的添加,假设答案有错误,希望大家能够指正 1.简述Activity的生命周期 当Activity開始启动的时候,首先调用onCre ...
- android 反编译和代码解读
二 错误代码还原规则 if…else 语句: 反编译代码 if (paramBoolean) paramTextView.setTextColor(-16727809); while (true) { ...
- matplotlib 可视化 —— 绘制常见图形
0. 饼状图 plt.pie():Python数据可视化:饼状图 1. 三角形 描点连线,起点和终点相同 triangle1 = ((0, sqrt(3)/2), (1, 3*sqrt(3)/2), ...
- django 笔记12 session
第一步写好函数,然后生成数据库session表 python manage.py makemigrations python manage.py migrate session原理: .Session ...
- ThinkPhp5-PHPExcel导出数据
PHP-Excel 标签(空格分隔): php 类库下载地址:https://codeload.github.com/PHPOffice/PHPExcel/zip/1.8 php导出excel表格数据 ...
- 3.bind与仿函数以及普通函数
#include <iostream> #include <string> #include <vector> #include <algorithm> ...