【BZOJ4276】[ONTAK2015]Bajtman i Okrągły Robin 线段树优化建图+费用流
【BZOJ4276】[ONTAK2015]Bajtman i Okrągły Robin
Description
Input
Output
Sample Input
1 4 40
2 4 10
2 3 30
1 3 20
Sample Output
题解:建图方法很简单,直接上了:
1.S -> 每个时间点i 费用0,容量1
2.[a,b]中的所有时间点 -> 盗贼j 费用0,容量1
3.盗贼j -> T 费用c,容量1
发现边数太多,用线段树优化建图即可。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define lson x<<1
#define rson x<<1|1
using namespace std;
int S,T,cnt,n,m,now,ans,L,R;
int to[3000000],next[3000000],cost[3000000],flow[3000000],head[100000],dis[100000],inq[100000];
int pv[100000],pe[100000],A[100000],B[100000],C[100000];
queue<int> q;
void add(int a,int b,int c,int d)
{
to[cnt]=b,cost[cnt]=c,flow[cnt]=d,next[cnt]=head[a],head[a]=cnt++;
to[cnt]=a,cost[cnt]=-c,flow[cnt]=0,next[cnt]=head[b],head[b]=cnt++;
}
void build(int l,int r,int x)
{
if(l==r)
{
add(S,x,0,1),now=max(now,x);
return ;
}
int mid=l+r>>1;
build(l,mid,lson),build(mid+1,r,rson);
add(lson,x,0,mid-l+1),add(rson,x,0,r-mid);
}
void updata(int l,int r,int x,int a,int b)
{
if(a<=l&&r<=b)
{
add(x,now,0,1);
return ;
}
int mid=l+r>>1;
if(a<=mid) updata(l,mid,lson,a,b);
if(b>mid) updata(mid+1,r,rson,a,b);
}
int bfs()
{
memset(dis,0x3f,sizeof(dis));
int i,u;
dis[S]=0,q.push(S);
while(!q.empty())
{
u=q.front(),q.pop(),inq[u]=0;
for(i=head[u];i!=-1;i=next[i])
{
if(dis[to[i]]>dis[u]+cost[i]&&flow[i])
{
dis[to[i]]=dis[u]+cost[i],pv[to[i]]=u,pe[to[i]]=i;
if(!inq[to[i]]) inq[to[i]]=1,q.push(to[i]);
}
}
}
return dis[T]<0x3f3f3f3f;
}
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;
}
int main()
{
n=rd();
int i,a,b,c;
S=0,L=5000,R=1;
memset(head,-1,sizeof(head));
for(i=1;i<=n;i++) A[i]=rd(),B[i]=rd()-1,C[i]=-rd(),L=min(L,A[i]),R=max(R,B[i]);
build(L,R,1);
T=n+now+1;
for(i=1;i<=n;i++) now++,updata(L,R,1,A[i],B[i]),add(now,T,C[i],1);
while(bfs())
{
int mf=1<<30;
for(i=T;i!=S;i=pv[i]) mf=min(mf,flow[pe[i]]);
ans+=mf*dis[T];
for(i=T;i!=S;i=pv[i]) flow[pe[i]]-=mf,flow[pe[i]^1]+=mf;
}
printf("%d",-ans);
return 0;
}
【BZOJ4276】[ONTAK2015]Bajtman i Okrągły Robin 线段树优化建图+费用流的更多相关文章
- BZOJ_4276_[ONTAK2015]Bajtman i Okrągły Robin_线段树优化建图+最大费用最大流
BZOJ_4276_[ONTAK2015]Bajtman i Okrągły Robin_线段树优化建图+最大费用最大流 Description 有n个强盗,其中第i个强盗会在[a[i],a[i]+1 ...
- BZOJ 4276: [ONTAK2015]Bajtman i Okrągły Robin [线段树优化建边]
4276: [ONTAK2015]Bajtman i Okrągły Robin 题意:\(n \le 5000\)个区间\(l,r\le 5000\),每个区间可以选一个点得到val[i]的价值,每 ...
- BZOJ4276 : [ONTAK2015]Bajtman i Okrągły Robin
建立线段树, S向每个叶子连边,容量1,费用0. 孩子向父亲连边,容量inf,费用0. 每个强盗向T连边,容量1,费用为c[i]. 对应区间内的点向每个强盗,容量1,费用0. 求最大费用流即可. #i ...
- [ONTAK2015]Bajtman i Okrągły Robin
bzoj 4276: [ONTAK2015]Bajtman i Okrągły Robin Time Limit: 40 Sec Memory Limit: 256 MB Description 有 ...
- 4276: [ONTAK2015]Bajtman i Okrągły Robin
4276: [ONTAK2015]Bajtman i Okrągły Robin Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 345 Solved ...
- BZOJ 4276: [ONTAK2015]Bajtman i Okrągły Robin
最大权值匹配,贪心匈牙利即可. 检查一些人是否能被全部抓住可以采用左端点排序,右端点优先队列处理. By:大奕哥 #include<bits/stdc++.h> using namespa ...
- BZOJ 4276 [ONTAK2015]Bajtman i Okrągły Robin 费用流+线段树优化建图
Description 有n个强盗,其中第i个强盗会在[a[i],a[i]+1],[a[i]+1,a[i]+2],...,[b[i]-1,b[i]]这么多段长度为1时间中选出一个时间进行抢劫,并计划抢 ...
- bzoj 4276: [ONTAK2015]Bajtman i Okrągły Robin【线段树+最大费用最大流】
--因为T点忘记还要+n所以选小了所以WA了一次 注意!题目中所给的时间是一边闭一边开的区间,所以读进来之后先l++(或者r--也行) 线段树优化建图,很神.(我记得还有个主席树优化建树的?)首先考虑 ...
- Bajtman i Okrągły Robin
Bajtman i Okrągły Robin 题目描述 你是一个保安,你发现有n个强盗,其中第i个强盗会在[a[i],a[i]+1],[a[i]+1,a[i]+2],...,[b[i]-1,b[i] ...
随机推荐
- interview fb2
2014.7.8fb #include <iostream> using namespace std; struct TreeNode{ int val; TreeNode *left; ...
- 2018年东北农业大学春季校赛 E 阶乘后的0【数论】
链接:https://www.nowcoder.com/acm/contest/93/E来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言52428 ...
- 洛谷——P1713 麦当劳叔叔的难题
P1713 麦当劳叔叔的难题 题目描述 话说我们铭铭小朋友成功的回答了爸爸的问题,自然少不了要去索要些奖励,抠门的爸爸一看报纸,嘿,门口的麦当劳在搞活动,还有免费午餐哦,不过前提条件:得正确回答麦当劳 ...
- Linux下Shell脚本字符串单引号、双引号、反引号、反斜杠的作用和区别
一.单引号 str='this is a string' 单引号字符串的限制: 单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的: 单引号字串中不能出现单引号(对单引号使用转义符后也不行) ...
- 【python】redis基本命令和基本用法详解
[python]redis基本命令和基本用法详解 来自http://www.cnblogs.com/wangtp/p/5636872.html 1.redis连接 redis-py提供两个类Redis ...
- linux命令lsattr、chattr、man
1.man命令,可以查看手册 配置位置/etc/man.conf MANPATH决定手册查询位置 MANSECT决定man查询的顺序 man的查询 linux man的常用用法: man sectio ...
- python tcp,udp简单使用
import socket host = '127.0.0.1' port = 9999 #创建一个tcp socket套接字 tcp_server = socket.socket(socket.AF ...
- appium 'WebDriver' object has no attribute 'keyevent'
这个问题是我自己犯二了,开头应该是from appium import webdriver,写成了from selenium import webdriver,也可以运行,就是不能使用appium中独 ...
- 黑苹果+win10双系统折腾笔记
寒假趁机在家折腾一下黑苹果 笔记本配置:神船K610D I7 4600 ,其他配置思路一样,驱动要自己找 镜像和工具:OS X Yosemite 10.10.3 镜像 WIN10 TLSB 2016 ...
- 【音乐App】—— Vue-music 项目学习笔记:项目准备
前言: 学习慕课网Vue高级实战课程后,在实践中总结一些这个项目带给自己的收获,希望可以再次巩固关于Vue开发的知识.这一篇主要梳理:项目概况.项目准备.页面骨架搭建.项目github地址:https ...