HDU4185 【二分图最大匹配】
来源:互联网 发布:第三方数据平台 编辑:程序博客网 时间:2024/06/14 00:40
Thanks to a certain "green" resources company, there is a new profitable industry of oil skimming. There are large slicks of crude oil floating in the Gulf of Mexico just waiting to be scooped up by enterprising oil barons. One such oil baron has a special plane that can skim the surface of the water collecting oil on the water's surface. However, each scoop covers a 10m by 20m rectangle (going either east/west or north/south). It also requires that the rectangle be completely covered in oil, otherwise the product is contaminated by pure ocean water and thus unprofitable! Given a map of an oil slick, the oil baron would like you to compute the maximum number of scoops that may be extracted. The map is an NxN grid where each cell represents a 10m square of water, and each cell is marked as either being covered in oil or pure water.
16.......##....##.......#.....##......
Case 1: 3
和POJ3020类似
题意:给一张图,问最大的连续两个格子数目有多少。
建图:用横纵坐标和为偶数为x边,对该点想上下左右寻找(上下左右点必为奇数为y边),建二分图。用匈牙利算法就行啦。
#include<cstring>#include<cstdio>#include<iostream>#include<algorithm>#include<vector>#include<queue>using namespace std;const int INF=0x3f3f3f3f;char mp[666][666];vector<int> g[1999];int n,m,mm,my[1999],ct[666][666];int dx[]={0,0,-1,1},dy[]={1,-1,0,0};bool vis[1999];int dfs(int x){ for(int i=0;i<g[x].size();i++) { int y=g[x][i]; if(vis[y])continue; vis[y]=true; if(my[y]==-1||dfs(my[y])) { my[y]=x; return 1; } } return 0;}int maxmacth(){ int ret=0,x,y; memset(my,-1,sizeof(my)); for(int i=1;i<=m;i++) { memset(vis,false,sizeof(vis)); if(dfs(i))ret++; } return ret;}int main(){ int tat,x,y,cas=1; scanf("%d",&tat); while(tat--) { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf(" %s",mp[i]+1); } m=mm=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if((i+j)%2) ct[i][j]=++m; else ct[i][j]=++mm; } } for(int i=1;i<=m;i++) { g[i].clear(); } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if((i+j)%2)continue; if(mp[i][j]=='#') for(int k=0;k<4;k++) { x=i+dx[k]; y=j+dy[k]; if(x<1||y<1||x>n||y>n)continue; if(mp[x][y]!='#')continue; g[ct[i][j]].push_back(ct[x][y]); } } } /* for(int i=1;i<=m;i++) { for(int j=0;j<g[i].size();j++) cout<<i<<" "<<g[i][j]<<endl; } */ printf("Case %d: %d\n",cas++,maxmacth()); } return 0;}
阅读全文
0 0
- hdu4185(二分图+最大匹配)
- HDU4185 【二分图最大匹配】
- hdu4185最大二分匹配
- hdu4185 二分图之最大匹配
- HDU4185 Oil Skimming-二分匹配
- hdu4185 Oil Skimming (最大匹配)
- HDU4185 Oil Skimming(二分图匹配,匈牙利算法)
- 【HDU4185】【最大二分匹配】【无法确定uN,vN就结果/2】
- hdu4185 Oil Skimming(二分匹配)
- 二分图最大匹配
- 二分图最大匹配 。
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图 最大匹配
- 二分图最大匹配
- 二分图最大匹配
- Android4.4之后以及7.0访问相册和裁剪相关问题
- 通过Python实现猜数字游戏
- linux下创建mysql用户,并且给增删改查的权限
- Linux 中断学习之前言篇---中断之原理篇
- 【转】C3P0连接池配置——ComboPooledDataSource
- HDU4185 【二分图最大匹配】
- 函数和递归(组合数,孪生素数,用指针实现变量交换,求解二院一次方程组)
- C++ lambda
- vue v-model
- C++学习之路(番外篇)
- 在linux安装JDK
- 保存文件到手机内存
- HDU 1213 How Many Tables 基础并查集★
- 截单返架系统分配货位优化