POJ2446
来源:互联网 发布:淘宝售前客服用语 编辑:程序博客网 时间:2024/05/18 01:42
Problem: Chessboard
Description: 拿一张
Solution: 一看这个问题我一开始想用
Code(C++):
#include <iostream>#include <vector>#include <string.h>#include <math.h>using namespace std;const int M=32*32+500;const int dirx[]={0,0,1,-1};const int diry[]={1,-1,0,0};bool used[M];int belong[M];int map[M][M];int n,m;int R,C,num;vector<int> to[M];bool dfs(int s){ for(int i=0;i<to[s].size();i++){ int end=to[s].at(i); if(used[end]) continue; used[end]=true; if(belong[end]==-1||dfs(belong[end])){ belong[end]=s; return true; } } return false;}int main(){ while(cin>>R>>C>>num){ n=m=0; for(int i=0;i<M;i++) to[i].clear(), belong[i]=-1; memset(map,0,sizeof(map)); for(int i=1;i<=num;i++){ int x,y; cin>>y>>x; map[x][y]=-1; } if(num%2){ cout<<"NO"<<endl; continue; } for(int i=1;i<=R;i++) for(int j=1;j<=C;j++) if(map[i][j]!=-1){ for(int k=0;k<4;k++){ int tx=i+dirx[k]; int ty=j+diry[k]; if(tx>=1&&tx<=R&&ty>=1&&ty<=C&& map[tx][ty]!=-1) ++m, to[(i-1)*32+j].push_back((tx-1)*32+ty); } ++n; } int ans=0; for(int i=1;i<=32*32;i++){ memset(used,false,sizeof(used)); if(dfs(i)) ++ans; } if(ans==n) cout<<"YES"; else cout<<"NO"; cout<<endl; } return 0;}
0 0
- poj2446
- poj2446
- poj2446
- POJ2446
- poj2446 Chessboard
- poj2446 Chessboard
- POJ2446 Chessboard
- poj2446 Chessboard
- POJ2446--Chessboard
- POJ2446 CHESSBOARD
- POJ2446【建图建图】
- POJ2446 二分图应用
- POJ2446:Chessboard(二分匹配)
- 【最大匹配】Chessboard POJ2446
- poj2446 Chessboard 二分匹配
- POJ2446 二分匹配
- poj2446--Chessboard(二分匹配)
- 二分图之poj2446
- mysql增删改查语句
- STM32F4_TIM输出PWM波形(可调频率、占空比)
- 经典排序算法--插入排序 希尔排序 归并排序
- CentOS7 安装Keepalived以及基本配置
- css3 box-sizing属性
- POJ2446
- JZOJ.4596 Stree
- AVA整合HTML5实现扫描二维码功能项目源码
- 图片工具类,照相,相册,剪裁,uri转换为string地址,缩放图片
- Network(图——割点 + 模板)
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) E. Package Delivery
- win、py、notepad++的编码方式及问题
- Android SwipeRefreshLayout 官方下拉刷新控件
- netty的http client连接池设计