【POJ】【P2446】【Chessboard】【题解】【二分图匹配】
来源:互联网 发布:mac口红 see sheer 编辑:程序博客网 时间:2024/05/19 18:37
传送门:http://poj.org/problem?id=2446
把空白格点标号,连接相邻格点,二分图匹配,注意xy是反着给出的,坑……
Code:
/*ID:iamzkyOJ:POJIndex:2446Language:C++*/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int map[51][51];int vis[2501];int w[2501][5];int Link[2501];int n,m,k;const int dx[4]={0,1,0,-1};const int dy[4]={1,0,-1,0};bool find(int x){for(int i=1;i<=w[x][0];i++){if(!vis[w[x][i]]){vis[w[x][i]]=1;if(!Link[w[x][i]]||find(Link[w[x][i]])){Link[w[x][i]]=x;return true;}}}return false;}int main(){while(cin>>m>>n>>k){for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)map[i][j]=-1;for(int i=1;i<=k;i++){int x,y;cin>>y>>x;map[x][y]=0;}int tot=0;for(int i=1;i<=m;i++)for(int j=1;j<=n;j++){if(map[i][j]!=-1)continue;map[i][j]=++tot;}if(tot%2){cout<<"NO"<<endl;break;//return 0;}for(int i=1;i<=m;i++)for(int j=1;j<=n;j++){for(int k=0;k<4;k++){int x=i+dx[k],y=j+dy[k];if(x<1||y<1||x>m||y>n||map[x][y]==0||map[i][j]==0)continue;w[map[i][j]][++w[map[i][j]][0]]=map[x][y];}}int ans=0;for(int i=1;i<=tot;i++){memset(vis,0,sizeof(vis));if(find(i))ans++;}//cout<<ans/2<<endl;if(ans==tot){cout<<"YES"<<endl;}elsecout<<"NO"<<endl;}return 0;}
0 0
- 【POJ】【P2446】【Chessboard】【题解】【二分图匹配】
- POJ P2446 Chessboard
- POJ 2446 Chessboard (二分图匹配)
- POJ 2446 Chessboard(二分图匹配)
- POJ 2446 Chessboard(二分图最大匹配)
- Chessboard - POJ 2446 二分图匹配
- POJ 2446 Chessboard(二分图匹配)
- POJ 2446 Chessboard(二分图匹配)
- POJ 2446 Chessboard(二分图最大匹配)
- POJ 2446 Chessboard(二分图匹配)
- poj--2446 Chessboard(二分图最大匹配)
- POJ 2446 Chessboard二分图匹配
- POJ 2446 Chessboard(二分图最大匹配)
- poj 2446(二分匹配) Chessboard
- Poj-2446 Chessboard 二分匹配
- 【POJ】2446 Chessboard 二分匹配
- 【二分图+最大匹配】北大 poj 2446 Chessboard
- poj 2446 Chessboard 二分图最大匹配经典题
- lua 最简单 网页抓取
- English_do
- web.xml配置文件详解
- acm.njupt--1859
- Struts2拦截器的使用 (详解)
- 【POJ】【P2446】【Chessboard】【题解】【二分图匹配】
- android初学------SlidingMenu(侧滑菜单的使用—)
- Structs2中配置文件详解
- 使用uIP将TUN网卡适配到TAP网卡-tun2tap
- 《高效学习OpenGL》 之 点块纹理 纹理矩阵堆栈 q坐标
- C#变量定义中类型后带一个问号
- kohana框架查询生成器
- SELECT语句逻辑执行顺序,你知道吗?
- Python学习笔记(五)—LOOP 循环