洛谷$P4001\ [ICPC-Beijing 2006]$狼抓兔子 网络流+对偶图
2024-09-07 10:18:58
正解:网络流+对偶图
解题报告:
$umm$日常看不懂题系列了$kk$.其实就是说,给定一个$n\cdot n$的网格图,求最小割$QwQ$
然后网格图的话显然是个平面图,又看到数据范围$n\leq 1000$,显然就考虑平面图转对偶图呗
然后好像就没有什么细节了,,,?
对了,$bzoj$上的话要特判1,洛谷上没有这个数据就不用辣$QwQ$
$QwQ$
(在$bzoj$上$T$了,,,应该是常数的问题懒得改了$QAQ$
#include<bits/stdc++.h>
using namespace std;
#define il inline
//#define int long long
#define fi first
#define sc second
#define gc getchar()
#define mp make_pair
#define P pair<int,int>
#define t(i) edge[i].to
#define w(i) edge[i].wei
#define ri register int
#define rb register bool
#define rc register char
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt) const int N=+;
int n,m,ed_cnt,head[N*N],S,T,dis[N*N];
struct ed{int to,nxt,wei;}edge[N*N*];
bool vis[N*N]; il int read()
{
rc ch=gc;ri x=;rb y=;
while(ch!='-' && (ch>'' || ch<''))ch=gc;
if(ch=='-')ch=gc,y=;
while(ch>='' && ch<='')x=(x<<)+(x<<)+(ch^''),ch=gc;
return y?x:-x;
}
il void ad(ri x,ri y,ri z){/*printf("%d -> %d : %d\n",y,x,z);*/edge[++ed_cnt]=(ed){x,head[y],z};head[y]=ed_cnt;}
il int nam(ri x,ri y,ri z){if(!x)return T;if(y>m)return T;if(!y)return S;if(x>n)return S;return (x*m-m+y)*+z;}
il void dij()
{
priority_queue< P,vector<P>,greater<P> >Q;Q.push(mp(,S));memset(dis,,sizeof(dis));
while(!Q.empty())
{
ri nw=Q.top().sc,diss=Q.top().fi;Q.pop();if(vis[nw])continue;vis[nw]=;dis[nw]=diss;
e(i,nw)if(!vis[t(i)])Q.push(mp(dis[nw]+w(i),t(i)));
}
} int main()
{
//freopen("4001.in","r",stdin);freopen("4001.out","w",stdout);
n=read()-;m=read()-;S=;T=n*m*+;
rp(i,,n+){rp(j,,m){ri tmp=read(),pos1=nam(i,j,-),pos2=nam(i-,j,);/*printf("%d ",tmp);*/ad(pos1,pos2,tmp);ad(pos2,pos1,tmp);}/*printf("\n");*/}
//printf("---\n");
rp(i,,n){rp(j,,m+){ri tmp=read(),pos1=nam(i,j,),pos2=nam(i,j-,-);/*printf("%d ",tmp);*/ad(pos1,pos2,tmp);ad(pos2,pos1,tmp);}/*printf("\n");*/}
//printf("---\n");
rp(i,,n){rp(j,,m){ri tmp=read(),pos1=nam(i,j,-),pos2=nam(i,j,);/*printf("%d ",tmp);*/ad(pos1,pos2,tmp);ad(pos2,pos1,tmp);}/*printf("\n");*/}
//printf("---\n");
//printf("---------\n");
//rp(i,1,n-1)rp(j,1,m-1)printf("%d %d (%d,%d)\n",nam(i,j,0),nam(i,j,-1),i,j);
dij();printf("%d\n",dis[T]);
return ;
}
//if(m==1 || n==1) tepan!!!
不开$O2$好像过不去,,,$QAQ$
最新文章
- JS高级程序设计&#160;笔记
- HDU4971 A simple brute force problem.(强连通分量缩点 + 最大权闭合子图)
- Selenium--cssselector
- HW2.23
- CentOS 6.4 使用YUM 安装MySQL5.5
- Office在线预览及PDF在线预览的实现方式史上最全大集合
- 解决IE6 IE7 JSON.stringify JSON 未定义问题
- 关于Winsock编程中IO重叠的概念
- 【1】JavaScript编程全解笔记(一)
- ecshop 后台添加新的设置
- HTML5 - Canvas动画样例(谷歌弹跳球)
- 【html5】html5离线存储
- 程序中编写log日志
- CentOS配置history记录每个用户执行过的命令
- pytorch入门与实践-2.2-CIFAR10分类网络
- hdu 2825
- Page5:状态转移矩阵及性质、连续线性系统离散化及其性质[Linear System Theory]
- spring cloud: Hystrix(二):简单使用@HystrixCommand的commandProperties配置@HistrixProperty隔离策略
- Oracle中sysdba身份和dba角色区别
- 超炫酷的jQuery/HTML5应用效果及源码