【BZOJ5037】[Jsoi2014]电信网络 最大权闭合图
【BZOJ5037】[Jsoi2014]电信网络
Description
Input
Output
输出一行一个整数,表示可以获得的最大收益。
Sample Input
0 1 7 10
0 -1 7 10
5 0 1 -15
10 0 6 10
15 1 2 -20
Sample Output
【样例说明】
我们可以将前三座基站升级成 3G 网络,以获得最佳收益。
题解:显然是一个最大权闭合图的模型,直接上建图方法:
1.S->所有正权的点 容量:该点权权值
2.所有负权的点->T 容量:该点权值相反数
3.点>所有它能发射到的点 容量:inf
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
int n,cnt,ans,S,T;
int x[510],y[510],r[510],s[510];
int to[1000000],next[1000000],val[1000000],head[510],d[510];
queue<int> q;
inline int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-')f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+gc-'0',gc=getchar();
return ret*f;
}
void add(int a,int b,int c)
{
to[cnt]=b,val[cnt]=c,next[cnt]=head[a],head[a]=cnt++;
to[cnt]=a,val[cnt]=0,next[cnt]=head[b],head[b]=cnt++;
}
int dfs(int x,int mf)
{
if(x==T) return mf;
int i,k,temp=mf;
for(i=head[x];i!=-1;i=next[i])
{
if(d[to[i]]==d[x]+1&&val[i])
{
k=dfs(to[i],min(val[i],temp));
if(!k) d[to[i]]=0;
val[i]-=k,val[i^1]+=k,temp-=k;
if(!temp) break;
}
}
return mf-temp;
}
int bfs()
{
while(!q.empty()) q.pop();
memset(d,0,sizeof(d));
q.push(S),d[S]=1;
int i,u;
while(!q.empty())
{
u=q.front(),q.pop();
for(i=head[u];i!=-1;i=next[i])
{
if(!d[to[i]]&&val[i])
{
d[to[i]]=d[u]+1;
if(to[i]==T) return 1;
q.push(to[i]);
}
}
}
return 0;
}
int main()
{
n=rd(),S=0,T=n+1;
int i,j;
memset(head,-1,sizeof(head));
for(i=1;i<=n;i++)
{
x[i]=rd(),y[i]=rd(),r[i]=rd(),s[i]=rd();
if(s[i]>0) ans+=s[i],add(S,i,s[i]);
else add(i,T,-s[i]);
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++) if(i!=j&&(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<=r[i]*r[i]) add(i,j,1<<30);
}
while(bfs()) ans-=dfs(S,1<<30);
printf("%d",ans);
return 0;
}
【BZOJ5037】[Jsoi2014]电信网络 最大权闭合图的更多相关文章
- BZOJ5037[Jsoi2014]电信网络——最大权闭合子图
题目描述 JYY创建的电信公司,垄断着整个JSOI王国的电信网络.JYY在JSOI王国里建造了很多的通信基站.目前所有的基站 都是使用2G网络系统的.而现在3G时代已经到来了,JYY在思考,要不要把一 ...
- 【TYVJ】1338 QQ农场(最大流+最大权闭合图)
http://tyvj.cn/Problem_Show.aspx?id=1338 时间才排到rank7,还不快啊囧.isap我常数都写得那么小了... 最大权闭合图看我另一篇博文吧 此题很明显的模型. ...
- POJ 2987 Firing【最大权闭合图-最小割】
题意:给出一个有向图,选择一个点,则要选择它的可以到达的所有节点.选择每个点有各自的利益或损失.求最大化的利益,以及此时选择人数的最小值. 算法:构造源点s汇点t,从s到每个正数点建边,容量为利益.每 ...
- POJ 2987 Firing 网络流 最大权闭合图
http://poj.org/problem?id=2987 https://blog.csdn.net/u014686462/article/details/48533253 给一个闭合图,要求输出 ...
- hdu 2987最大权闭合图模板类型题
/* 最大权闭合图模板类型的题,考验对知识概念的理解. 题意:如今要辞退一部分员工.辞退每个员工能够的到一部分利益(能够是负的),而且辞退员工,必须辞退他的下属.求最大利益和辞退的最小人数. 最大权闭 ...
- POJ2987 Firing 【最大权闭合图】
POJ2987 Firing Description You've finally got mad at "the world's most stupid" employees o ...
- POJ 2987 Firing(最大流最小割の最大权闭合图)
Description You’ve finally got mad at “the world’s most stupid” employees of yours and decided to do ...
- poj 2987(最大权闭合图+割边最少)
题目链接:http://poj.org/problem?id=2987 思路:标准的最大权闭合图,构图:从源点s向每个正收益点连边,容量为收益:从每个负收益点向汇点t连边,容量为收益的相反数:对于i是 ...
- POJ 2987 Firing(最大权闭合图)
[题目链接] http://poj.org/problem?id=2987 [题目大意] 为了使得公司效率最高,因此需要进行裁员, 裁去不同的人员有不同的效率提升效果,当然也有可能是负的效果, 如果裁 ...
随机推荐
- java中XML操作:xml与string互转、读取XML文档节点及对XML节点增删改查
一.XML和String互转: 使用dom4j程式变得很简单 //字符串转XML String xmlStr = \"......\"; Document document = D ...
- Spring获取properties文件中的属性
1.前言 本文主要是对这两篇blog的整理,感谢作者的分享 Spring使用程序方式读取properties文件 Spring通过@Value注解注入属性的几种方式 2.配置文件 applicatio ...
- scrapy爬虫程序xpath中文编码报错
2017-03-23 问题描述: #选择出节点中“时间”二字 <h2>时间</h2> item["file_urls"]= response.xpath(& ...
- Angular 学习笔记——ng-disable
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...
- Go语言格式化字符
https://github.com/polaris1119/The-Golang-Standard-Library-by-Example/blob/master/chapter01/01.3.md
- Oracle 左外连接的一些測试
为了更加深入左外连接,我们做一些測试,外连接的写法有几种形式,我们能够通过10053跟踪到终于SQL转换的形式. --初始化数据 create table A ( id number, age ...
- JQuery修改对象的属性值
JQuery修改对象的属性值 用到的便是JQuery提供的attr方法,获取属性值的基本结构为:$(obj).attr("属性名"):修改属性值的结构为:$(obj).attr(& ...
- tail -f 不断刷新
查看log tail -f 会将其不断刷新显示
- 我攻克了oom
BitmapFactory.Options options=new BitmapFactory.Options(); options.inJustDecodeBounds = false; ...
- 在服务端发起一个Post请求
1.http://www.tuling123.com/openapi/api?key=9d2ff29d44b54e55acadbf5643569584&info=? 上面这个请求在服务端发起 ...