Battle ships
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others) total submission (s): 1007 Accepted Submission (s): 353
Problem Descriptiondear contestant, now a excellent Navy commander, who is responsible of a tough mission Ly.
Your Fleet Unfortunately encountered an enemy fleet near the South Pole where the geographical conditions is negative for Both sides. The floating ice and iceberg blocks battleships move which leads to this unexpected engagement highly dangerous, unpredict Able and incontrollable.
But, fortunately, as a experienced navy commander, you is able to take opportunity-embattle the ships to maximize the Utility of cannons on the battleships before the engagement.
The target is a arrange as many battleships as you can in the map. However, there is three rules so which you cannot does that arbitrary:
A battleship cannot lay on floating ice A battleship cannot being placed on an iceberg
The battleships cannot is arranged in the same row or column, and unless one or more icebergs is in the middle of them.
Inputthere is only one of the integer T (0<t<12) at the beginning line, which means following T test cases.
For each test case, integers m and n (1 <= m, n <=) is at the first line, represents the number of rows and Columns of the battlefield map respectively. Following m lines contains n characters iteratively, each character belongs to one of the ' # ', ' * ', ' o ', that symbolize iceber G, ordinary sea and floating ice.
Outputfor each case, output just one line, contains a single integer which represents the maximal possible number of Battl Eships can be arranged.
Sample Input24 4*oooo###**#*ooo*4 4#****#****#*ooo#
Sample Output35
Problem: Test instructions is to find in this matrix can be placed in the maximum number of ships, among them can have icebergs, ships without icebergs when the ship can not be in the same row; This needs to be built, first scan line, if you encounter Iceberg t++; The next number can continue to match, the next line is t++, and again, the scan column To obtain a binary matching x division and Y Division;
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include < Algorithm> #include <vector>using namespace std;const int Inf=0x3f3f3f3f;const double Pi=acos ( -1.0); #define Mem (x, y) memset (x,y,sizeof) typedef long long LL; #define SI (x) scanf ("%d", &x) #define SL (x) scanf ("%lld", &x) # Define T_T while (t--) #define F (i,x) for (i=0;i<x;i++) #define PR (x) printf ("%d", x) #define PL (x) printf ("%lld", x) # Define P_ printf ("") const int Maxn=1010;char s[maxn][maxn];int mp[maxn][maxn],vis[maxn],link[maxn],x[110][110],y[110 ][110];int m,n,t1,t2;int getmpxy (int rl,int a[][110]) {//scan rows and columns to get binary matching x and y int t=0,i,j;if (RL) F (i,m) {f (j,n) {if (S[i][j] = = ' * ') a[i][j]=t;if (s[i][j]== ' # ') t++;} t++;} else F (J,n) {f (i,m) {if (s[i][j]== ' * ') a[i][j]=t;if (s[i][j]== ' # ') t++;} t++;} return t;} void Getmp () {mem (x,0); mem (y,0); T1=getmpxy (1,x); T2=getmpxy (0,y); int i,j; F (i,m) {f (j,n) {if (s[i][j]== ' * ') {//printf ("%d%d\n", x[i][j],y[i][j]); mp[x[i][j]][y[i][j]]=1;}}} bool Dfs (int x) {int i,j; F (i,t2) {if (!vis[i]&&mp[x][i]) {vis[i]=1;if (link[i]==-1| | DFS (Link[i])) {//| | link[i]=x;return true;}}} return false;} Int. km () {mem (link,-1); int I,j;int ans=0; F (I,T1) {mem (vis,0); if (Dfs (i)) ans++;} return ans;} int main () {int t;si (T); T_t{si (m); SI (n); int i,j;mem (mp,0); F (i,m) scanf ("%s", S[i]); getmp (); PR (km ());p UTS ("");} return 0;}
Battle ships (binary map, building map, good title)