Poj Muddy Fields, pojmuddyfields
Muddy Fields
Find the original question in the topic I created and go to the home page of the directory.
Question:
The N * M matrix is given, where * Indicates dirt and. Indicates grass. You need to cover the earth with the least wooden boards. The length of the board is not limited, but it can only be horizontal or vertical.
Two-point matching of the determinant. Is an enhanced version of the poj3041 graph.
Algorithm:
Inspired by the building of poj3041, the wood board is treated as the vertex, the X axis, and the Y axis as the edge. Solve the minimum vertex overwrite.
There is no obstacle in the laser beam of 3041, but there is no restriction on the damage to the grass.
We can think from another angle. Since we cannot crush the grass, it is equivalent to the laser which must be stopped when it reaches here. Therefore, we will use the grass as the boundary for graph analysis. Every time you encounter a grass, it is done as a row or a column to the header. This is a normal Binary Graph.
The data for T_T is 25*25, which is the upper limit. Because, in the worst case, grass and dirt appear.
In addition, when making questions in the future, especially for Matrix input, you must pay attention to the problem of inputting rows and columns !!!!!!!!!
Tears are everywhere !!!!
/* When the wooden boards covered by the row and column are treated as points, each grid becomes an edge, the problem is converted to the minimum vertex overwrite problem */# include <iostream> # include <algorithm> # include <vector> # include <cstdio> # include <cstring> using namespace std; const int MAXN = 50 + 10; const int MAXV = 1500; vector <int> G [MAXV]; char mp [MAXN] [MAXN]; int numx [MAXN] [MAXN], numy [MAXN] [MAXN]; int match [MAXV]; bool used [MAXV]; int N, M, V; void init () {for (int I = 0; I <= N * M; ++ I) G [I]. clear ();} bool dfs (int u) {for (int I = 0; I <(int) G [u]. size (); ++ I) {int v = G [u] [I]; if (! Used [v]) {used [v] = 1; if (match [v] =-1 | dfs (match [v]) {match [v] = u; return true ;}} return false;} void solve () {int res = 0; memset (match,-1, sizeof (match); for (int I = 1; I <= V; ++ I) {memset (used, 0, sizeof (used )); if (dfs (I) res ++;} printf ("% d \ n", res);} int main () {// freopen ("Input.txt ", "r", stdin); while (~ Scanf ("% d", & N, & M) {init (); for (int I = 0; I <N; ++ I) {scanf ("% s", mp [I]);} int cnt = 0; memset (numx, 0, sizeof (numx); memset (numy, 0, sizeof (numy); for (int I = 0; I <N; ++ I) for (int j = 0; j <M; ++ j) if (mp [I] [j] = '*') {++ cnt; while (j <M & mp [I] [j] = '*') {numx [I] [j] = cnt; ++ j ;}} V = cnt; for (int j = 0; j <M; ++ j) for (int I = 0; I <N; ++ I) if (mp [I] [j] = '*') {++ cnt; while (I <N & mp [I] [j] = '*') {numy [I] [j] = cnt; ++ I ;}} for (int I = 0; I <N; ++ I) {for (int j = 0; j <M; ++ j) {if (numx [I] [j] & numy [I] [j]) {G [numx [I] [j]. push_back (numy [I] [j]) ;}} solve () ;}return 0 ;}
I encountered a problem when I was doing Peking University's "baiti" OpenJudge. I cannot use the pow function. How can I use pow in poj?
# Include <cstdio>
# Include <cmath>
# Include <string>
# Include <string. h>
# Include <stdlib. h>
# Include <memory. h>
Using namespace std;
If (! M_RecoBool) return 0;
Data. TrimLeft ();
Data. TrimRight ();
HRESULT hr;
Field * field = NULL;
Fields * fields = NULL;
DataTypeEnum type;
_ Variant_t null;
Null. vt = VT_ERROR;
ERROR _
_ Variant_t name = Name;
Name. vt = VT_BSTR;
_ Variant_t data;
Hr = m_RecoPtr-> get_Fields (& fields );
If (! SUCCEEDED (hr) return 0;
Hr = fields-> get_Item (name, & field );
If (! SUCCEEDED (hr) return 0;
Hr = field-> get_Type (& type );
If (! SUCCEEDED (hr) return 0;
If (! FaxStringToVariant (Data, type, & data ))
Return 0;
// Change the column Value
Hr = field-> put_Value (data );
M_UpdateBool = 1;
If (! SUCCEEDED (hr) return 0;
If (fields) fields-> Release ();
If (field) field-> Release ();
ERROR_END_R0