bzoj2257[POI2011]Programming Contest
首先可以费用流建图,左边一堆点表示人,右边一堆点表示题,源点向每个人连floor(t/r)条边,费用依次为r,2r,3r….然后写了一个卡不过去,动态加边也卡不过去,然后我想:这里一定有一些不为人知的卡常黑科技!然后去查题解发现不是费用流…因为只有源点向人的连边有费用,那么费用流的过程其实是:考虑让尽量多的人做费用为r的第一道题,然后让尽量多的人做费用为2r的第二道题…然后我们发现,写一个动态加边的dinic就可以了…我这里没有加边,直接把源点向人连边的边权重置,效果是一样的.
边权重置之后就不能沿着反向边反悔了,但这道题的性质使得不考虑反悔的情况也是对的.如果考虑费用为r的时候让1号人做了1号题,然后考虑费用为2r的时候发现可以让2号人做1号题,1号人做2号题,这种情况是不会出现的,因为在考虑费用为r的时候就可以让2号人做1号题,1号人做2号题.
一开始跑费用流T了好几发,然后dinic当前弧优化写残了又T了好几发...
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=,maxm=;
struct edge{
int to,next,w;
}lst[maxm];int len=,first[maxn],_first[maxn];
void addedge(int a,int b,int w){
lst[len].to=b;lst[len].next=first[a];lst[len].w=w;first[a]=len++;
lst[len].to=a;lst[len].next=first[b];lst[len].w=;first[b]=len++;
}
int q[maxn],dis[maxn],vis[maxn],s,t,head,tail,T;
bool bfs(){
head=tail=;vis[s]=++T;dis[s]=;q[tail++]=s;
while(head!=tail){
int x=q[head++];
for(int pt=first[x];pt!=-;pt=lst[pt].next){
if(lst[pt].w&&vis[lst[pt].to]!=T){
dis[lst[pt].to]=dis[x]+;vis[lst[pt].to]=T;q[tail++]=lst[pt].to;
}
}
}
if(vis[t]==T)memcpy(_first,first,sizeof(first));
return vis[t]==T;
}
int dfs(int x,int lim){
if(x==t)return lim;
int flow=,a;
for(int pt=_first[x];pt!=-;pt=lst[pt].next){
_first[x]=pt;
if(lst[pt].w&&dis[lst[pt].to]==dis[x]+&&(a=dfs(lst[pt].to,min(lst[pt].w,lim-flow)))){
lst[pt].w-=a;lst[pt^].w+=a;flow+=a;
if(lim==flow)return lim;
}
}
return flow;
}
int dinic(){
int ans=,x;
while(bfs())while(x=dfs(s,0x7f7f7f7f))ans+=x;
return ans;
}
int n,m,r,lim,k;
int main(){
memset(first,-,sizeof(first));
scanf("%d%d%d%d%d",&n,&m,&r,&lim,&k);
s=;t=n+m+;
for(int i=;i<=m;++i)addedge(n+i,t,);
int a,b;
for(int i=;i<=k;++i){
scanf("%d%d",&a,&b);
addedge(a,n+b,);
}
int ans1=,ans2=;
for(int i=;i<=n;++i)addedge(s,i,);
for(int j=;j*r<=lim;++j){
int tmp=dinic();ans1+=tmp;ans2+=tmp*j*r;
if(tmp==)break;
for(int i=;i<=n;++i){
lst[len-i*].w=;lst[len-i*+].w=;
}
}
printf("%d %d\n",ans1,ans2);
return ;
}
bzoj2257[POI2011]Programming Contest的更多相关文章
- BZOJ2557[Poi2011]Programming Contest——匈牙利算法+模拟费用流
题目描述 Bartie and his friends compete in the Team Programming Contest. There are n contestants on each ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- ZOJ 3703 Happy Programming Contest
偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds Memory Limit: 65536 ...
- Happy Programming Contest(ZOJ3703)(01背包+路径储存)
Happy Programming Contest ZOJ3703 老实说:题目意思没看懂...(希望路过的大神指点) 最后那个the total penalty time是什么意思啊!!! 还是学 ...
- The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540
Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
随机推荐
- SpaceVim 语言模块 elm
原文连接: https://spacevim.org/cn/layers/lang/elm/ 模块简介 功能特性 依赖安装及启用模块 依赖安装 启用模块 快捷键 语言专属快捷键 交互式编程 模块简介 ...
- angularjs transitions
http://angular-transitions.mgechev.com/#/view/page1 https://scotch.io/tutorials http://stackoverflow ...
- BZOJ2659_算不出的算式_KEY
题目传送门 其实打表找一找规律可以得出: /************************************************************** Problem: 2659 U ...
- 西安Uber优步司机奖励政策(12月21日-12.27日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- COGS 2199. [HZOI 2016] 活动投票
2199. [HZOI 2016] 活动投票 ★★ 输入文件:hztp.in 输出文件:hztp.out 简单对比时间限制:0.5 s 内存限制:2 MB [题目描述] 衡中活动很多, ...
- LeetCode:40. Combination Sum II(Medium)
1. 原题链接 https://leetcode.com/problems/combination-sum-ii/description/ 2. 题目要求 给定一个整型数组candidates[ ]和 ...
- VIO概述 On-Manifold Preintegration for Real-Time Visual--Inertial Odometry
目前的研究方向可以总结为在滤波算法中实现高精度,在优化算法中追求实时性.当加入IMU后,研究方向分为松耦合和紧耦合,松耦合分别单独计算出IMU测量得到的状态和视觉里程计得到的状态然后融合,紧耦合则将I ...
- MySQL 取得字段子串修改
MySQL 中, GeneID 为 GRMZM2G549533_P01,1123,45 , 需要修改为 GRMZM2G549533_P01 update test set GeneID=SUBSTRI ...
- hdu1069Monkey and Banana(动态规划)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- “Hello World!团队”Alpha发布—视频链接+文案+美工
视频链接:http://v.youku.com/v_show/id_XMzEyNjc2MTAyOA==.html?sharefrom=iphone&sharekey=5378037f8b710 ...