二分图(行列变化)
来源:互联网 发布:小学生题目解答软件 编辑:程序博客网 时间:2024/04/29 19:48
HDU 4185 :
Problem Description
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.
Input
The input starts with an integer K (1 <= K <= 100) indicating the number of cases. Each case starts with an integer N (1 <= N <= 600) indicating the size of the square grid. Each of the following N lines contains N characters that represent the cells of a row in the grid. A character of '#' represents an oily cell, and a character of '.' represents a pure water cell.
Output
For each case, one line should be produced, formatted exactly as follows: "Case X: M" where X is the case number (starting from 1) and M is the maximum number of scoops of oil that may be extracted.
Sample Input
16.......##....##.......#.....##......
Sample Output
Case 1: 3
求图中"**"(竖着也可以)。
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<set>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int maxn=600+10;char s[maxn][maxn];int mp[maxn][maxn],id[maxn][maxn];int used[maxn],link[maxn];int dr[][2]={-1,0,1,0,0,-1,0,1};int t,n,cnt,cas;bool dfs(int x){ REP(i,cnt) { if(mp[x][i]&&!used[i]) { used[i]=true; if(link[i]==-1||dfs(link[i])) { link[i]=x; return true; } } } return false;}void work(){ int res=0; CLEAR(link,-1); REP(i,cnt) { CLEAR(used,0); if(dfs(i)) res++; } printf("Case %d: %d\n",cas++,res/2);}bool ok(int x,int y){ if(x<0||x>=n||y<0||y>=n) return false; return true;}int main(){ cas=1; scanf("%d",&t); while(t--) { scanf("%d",&n); cnt=1; CLEAR(id,0); REP(i,n) { scanf("%s",s[i]); REP(j,n) if(s[i][j]=='#') id[i][j]=cnt++;//编号 } CLEAR(mp,0); REP(i,n) { REP(j,n) { if(id[i][j]) { REP(k,4) { int xx=i+dr[k][0]; int yy=j+dr[k][1]; if(ok(xx,yy)&&id[xx][yy]) mp[id[i][j]][id[xx][yy]]=1; } } } } work(); } return 0;}
POJ 3020:
Description
The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. It is called 4DAir, and comes in four types. Each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the earth. The four types correspond to antennas operating in the directions north, west, south, and east, respectively. Below is an example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ellipses covering them.
Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered?
Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered?
Input
On the first row of input is a single positive integer n, specifying the number of scenarios that follow. Each scenario begins with a row containing two positive integers h and w, with 1 <= h <= 40 and 0 < w <= 10. Thereafter is a matrix presented, describing the points of interest in Sweden in the form of h lines, each containing w characters from the set ['*','o']. A '*'-character symbolises a point of interest, whereas a 'o'-character represents open space.
Output
For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.
Sample Input
27 9ooo**oooo**oo*ooo*o*oo**o**ooooooooo*******ooo*o*oo*oo*******oo10 1***o******
Sample Output
175
Source
Svenskt Mästerskap i Programmering/Norgesmesterskapet 2001
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<set>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int maxn=500+10;char s[maxn][maxn];int mp[maxn][maxn],id[maxn][maxn];int used[maxn],link[maxn];int dr[][2]={-1,0,1,0,0,-1,0,1};int t,n,m,cnt,cas;bool dfs(int x){ REPF(i,1,cnt) { if(mp[x][i]&&!used[i]) { used[i]=true; if(link[i]==-1||dfs(link[i])) { link[i]=x; return true; } } } return false;}void work(){ int res=0; CLEAR(link,-1); REPF(i,1,cnt-1) { CLEAR(used,0); if(dfs(i)) res++; } printf("%d\n",cnt-1-res/2);}bool ok(int x,int y){ if(x<0||x>=n||y<0||y>=m) return false; return true;}int main(){ cas=1; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); cnt=1; CLEAR(id,0); REP(i,n) { scanf("%s",s[i]); REP(j,m) if(s[i][j]=='*') id[i][j]=cnt++;//编号 } CLEAR(mp,0); REP(i,n) { REP(j,m) { if(id[i][j]) { REP(k,4) { int xx=i+dr[k][0]; int yy=j+dr[k][1]; if(ok(xx,yy)&&id[xx][yy]) mp[id[i][j]][id[xx][yy]]=1; } } } } work(); } return 0;}
0 0
- 二分图(行列变化)
- 二分图(行列匹配)
- HDU1498-二分图行列匹配
- HDU1507-二分图行列匹配
- HDU 2819 Swap (二分图-行列匹配+输出解)
- hdu1045——Fire Net(二分图+行列匹配)
- poj2226(*行列模型,二分图最小顶点覆盖)
- POJ 2226 行列拆分之二分图
- hdu 1045(dfs暴搜/缩点+二分图最大匹配(典型行列匹配题))
- 二分匹配--行列匹配
- poj2226 二分图匹配经典行列建图
- hdu1281 棋盘游戏(二分匹配+行列匹配)
- LightOJ 1137 Expanding Rods(加热变化的路,二分)
- PKU 3041 Asteroids - 行列的二分图模型 最小点覆盖
- hdu 3360 National Treasures 二分行列匹配
- hdu 1045 Fire Net 二分行列匹配
- [MySQL] 行列转换变化各种方法实现总结(行变列报表统计、列变行数据记录统计等)
- [MySQL] 行列转换变化各种方法实现总结(行变列报表统计、列变行数据记录统计等)
- html页面绑定代理事件
- MS脑筋急转弯系列1
- busybox制作文件系统2
- 58. Length of Last Word Leetcode Python
- td 内容自动换行 table表格td设置宽度后文字太多自动换行
- 二分图(行列变化)
- vm6.5,redhat5安装oracle11gR2
- 主成分分析(Principal components analysis)-最大方差解释
- 【零碎JAVA】web-编码问题
- NYOJ 题目998 Sum(欧拉函数,水)
- android实现音乐播放器(进度条)
- leetcode.20-----------Valid Parentheses
- 二分图(最大独立集)
- Android Studio系列教程二--基本设置与运行