博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Chessboard POJ - 2446(最大流 || 匹配)
阅读量:4511 次
发布时间:2019-06-08

本文共 2641 字,大约阅读时间需要 8 分钟。

there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th column.

呃呃呃呃呃。。。因为这个wa了一次

向周围建边就好了

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define rap(i, a, n) for(int i=a; i<=n; i++)#define rep(i, a, n) for(int i=a; i
=a; i--)#define lep(i, a, n) for(int i=n; i>a; i--)#define rd(a) scanf("%d", &a)#define rlld(a) scanf("%lld", &a)#define rc(a) scanf("%c", &a)#define rs(a) scanf("%s", a)#define rb(a) scanf("%lf", &a)#define rf(a) scanf("%f", &a)#define pd(a) printf("%d\n", a)#define plld(a) printf("%lld\n", a)#define pc(a) printf("%c\n", a)#define ps(a) printf("%s\n", a)#define MOD 2018#define LL long long#define ULL unsigned long long#define Pair pair
#define mem(a, b) memset(a, b, sizeof(a))#define _ ios_base::sync_with_stdio(0),cin.tie(0)//freopen("1.txt", "r", stdin);using namespace std;const int maxn = 1e5 + 10, INF = 0x7fffffff;int n, m, s, t, k;int hol[1100][1100];int dir[4][2] = { { 1, 0}, {-1, 0}, { 0, 1}, { 0, -1}};int head[maxn], cur[maxn], d[maxn], nex[maxn << 1];int cnt;struct node{ int u, v, c;}Node[maxn << 1];void add_(int u, int v, int c){ Node[cnt].u = u; Node[cnt].v = v; Node[cnt].c = c; nex[cnt] = head[u]; head[u] = cnt++;}void add(int u, int v, int c){ add_(u, v, c); add_(v, u, 0);}bool bfs(){ queue
Q; mem(d, 0); Q.push(s); d[s] = 1; while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int i = head[u]; i != -1; i = nex[i]) { int v = Node[i].v; if(!d[v] && Node[i].c > 0) { d[v] = d[u] + 1; Q.push(v); if(v == t) return 1; } } } return d[t] != 0;}int dfs(int u, int cap){ int ret = 0; if(u == t || cap == 0) return cap; for(int &i = cur[u]; i != -1; i = nex[i]) { int v = Node[i].v; if(d[v] == d[u] + 1 && Node[i].c > 0) { int V = dfs(v, min(Node[i].c, cap)); Node[i].c -= V; Node[i ^ 1].c += V; ret += V; cap -= V; if(cap == 0) break; } } if(cap > 0) d[u] = -1; return ret;}int Dinic(){ int ans = 0; while(bfs()) { memcpy(cur, head, sizeof head); ans += dfs(s, INF); } return ans;}int main(){ while(scanf("%d%d%d", &n, &m, &k) != EOF) { mem(head, -1); mem(hol, 0); cnt = 0; s = 0, t = 2000; int x, y; rap(i, 1, k) { scanf("%d%d", &y, &x); hol[x][y] = 1; } if((n * m - k) & 1) { ps("NO"); continue; } // cout << 111 <
n || ny < 1 || ny > m || hol[nx][ny]) continue; add((i - 1) * m + j, 1024 + (nx - 1) * m + ny, 1); } } // cout << Dinic() << endl; // cout << n * m if(Dinic() == n * m - k) { ps("YES"); } else { ps("NO"); } } return 0;}

 

转载于:https://www.cnblogs.com/WTSRUVF/p/10029253.html

你可能感兴趣的文章
爬虫实战篇---数据入库之去重与数据库
查看>>
CMPSC-132 – Programming and Computation
查看>>
RazorPad中的ModelProvider
查看>>
用于 Visual Studio 和 ASP.NET 的 Web 应用程序项目部署常见问题
查看>>
洛谷 P4878 [USACO05DEC] 布局
查看>>
Python MySQL Django一些问题
查看>>
OpenGL------显示列表
查看>>
第四次实验报告
查看>>
给mysql的root用户
查看>>
Mirror--镜像用户同步
查看>>
『科学计算』高斯判别分析模型实现
查看>>
『Pickle』数据结构持久化模块_常用方法记录
查看>>
pycharm 的包路径设置export PYTHONPATH=$PYTHONPATH
查看>>
SQL语句创建函数
查看>>
Git快速入门
查看>>
查找数组元素位置
查看>>
vue开发的打包配置
查看>>
jquery基础
查看>>
端口作用
查看>>
SpringAOP基础 - 静态代理设计模式
查看>>