HDU 4517 Xiao Xiao Ming series Story---game Trouble (simulated problem)

Source: Internet
Author: User
Tags ming

Problem Description:

Xiao Xiao Ming recently playing a game, it is composed of n*m size matrix, the matrix will randomly produce some black dots, these points they may be linked together may also be separated, the number of these points is not limited, but each 1*1 square can have a maximum of only one black point produced.  The game requires the player in the shortest time with x*y small matrix covering the large matrix, covering the requirements of the following 2 points: 1.   X*y size of small matrix must have x*y black dots. 2. Multiple small matrices can overlap, but each small matrix placement must be unique, that is, the black dots within different small matrices cannot be identical.   For example, the 1*2 matrix can be placed sideways or vertically, and these two methods are different, even though they may share black dots. Xiao Xiao Ming is a careless child, he tried many times can not all meet the requirements of the small matrix to find, smart you, can you tell the trouble in the small Ming this large matrix how many meet the requirements of the small matrix it?

Input:

the topic has multiple sets of test data (no more than 100); the first row of each set of test data contains 2 positive integers n and M, then the second line is x and Y (n,m,x,y), followed by n lines, with m characters per line, where ' * ' denotes black dots, '. ' Indicates a blank. N and M are 0 to end the input.

0 < N, M <= 2000

0 < X, y <= 1000

Output:

the topic has multiple sets of test data (no more than 100); the first row of each set of test data contains 2 positive integers n and M, then the second line is x and Y (n,m,x,y), followed by n lines, with m characters per line, where ' * ' denotes black dots, '. ' Indicates a blank. N and M are 0 to end the input.

0 < N, m <= 0 < x, y <= 1000

Sample input:

2 31 2**. **0 0

Sample output:

3

Problem Solving Ideas:

(1), using cnt[I [j] record the end of line I j, the length of the left continuous with * number;

(2), and then from top to bottom by column processing once,

(3) The length of each line with an * number is greater than or equal to the specified number of long/wide, when the Len1,len2 record is listed as the end of the line I J.

(4), add is the answer. Here's a trap that divides the answer by 2 when the small matrix row equals the column.

1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5 using namespacestd;6 #defineN 20057 intCnt[n][n];8 intMain ()9 {Ten     inti,j,n,c,r,m; One     CharCh[n]; A      while(SCANF ("%d%d", &n,&m) && n +m) -     { -scanf"%d%d",&c,&R); the         intAns =0; -          for(i =1; I <= n;i++) -         { -scanf"%s",&ch); +              for(j =1; J <= m;j++) -             { +  A                 intFlag = ch[j-1] =='*'?1:0; at             //cout<<ch[j-1]<<endl; -                 if(flag) -CNT[I][J] = cnt[i][j-1] +1; -                 Else -CNT[I][J] =0; -  in             } -         } to         intLen1,len2; +          for(i =1; I <= m;i++) -         { theLen1 = Len2 =0; *              for(j =1; J <= n;j++) $             {Panax Notoginseng             //cout<<cnt[j][i]<<endl; -                 if(Cnt[j][i] >= c) len1++; the                 ElseLen1 =0; +                 if(Len1 >=R) A                 { theAns + +; +                 } -                 if(Cnt[j][i] >= R) len2++; $                 ElseLen2 =0; $                 if(Len2 >=c) -                 { -ans++; the                 } -             }Wuyi         } the         if(c = =R) -Ans/=2; Wuprintf"%d\n", ans); -     } About     return 0; $}
View Code

HDU 4517 Xiao Xiao Ming series Story---game Trouble (simulated problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.