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 ...
随机推荐
- CF480Div2掉分记
rating 1900+参加只有Div2的比赛也记rating了.还以为yyc报名没打会惨惨,原来不交题好像就不算参加.. 本来太晚了不想打,不过有Sinogi大佬带我还是打一打吧,apio之前练练手 ...
- Splay初学习
例题传送门 听YZ哥哥说Splay是一种很神奇的数据结构,所以学习了一下它的最基本操作.O(1)的Spaly. 伸展树(Splay Tree),也叫分裂树,是一种二叉排序树,它能在O(logn)内完成 ...
- 【caffe范例详解】 - 1.Classification分类
1. 安装 首先,导入numpy和matplotlib库 # numpy是常用的科学计算库,matplot是常用的绘图库 import numpy as np import matplotlib.py ...
- 1030: [JSOI2007]文本生成器
1030: [JSOI2007]文本生成器 https://www.lydsy.com/JudgeOnline/problem.php?id=1030 分析: AC自动机+dp. 正难则反,求满足的, ...
- VINS(九)Ceres Solver优化(未完待续)
使用Ceres Solver库处理后端优化问题,首先系统的优化函数为
- CSS3 子节点选择器
CSS3中新增了几个子元素选择器,大大提高了开发者的开发效率.之前有些要通过为一个个子元素添加class,或者js实现才能实现的效果.现在可以很方便的用选择器实现. 这些新的样式已被现代浏览器及IE9 ...
- WPF & EF & Prism useful links
Prism Attributes for MEF https://msdn.microsoft.com/en-us/library/ee155691%28v=vs.110%29.aspx Generi ...
- Linux用户切换和密码修改
1.普通用户切换到root su - 再输入root密码,密码正确,成功切换,再输入exit则切换回普通用户 2.root切换到其他用户,例user su - user 再输入exit,则切换回roo ...
- uiautomatorviewer定位App元素
这个工具是Android SDK自带的, 日常的工作中经常要使用的, 在C:\Android\sdk\tools\bin目录下: 双击之, 请注意, 我一般选择第一个机器人小图标Device Scre ...
- 获取App的PackageName包名和LauncherActivity启动页
第一种情况: 查看手机里面已经安装的App: 用数据线连接手机, 打开开发者模式, 并赋予相关权限: 1. 清除日志: adb logcat -c 2. 启动日志: adb logcat Activi ...