JZOJ 1237. table

topic

Description

You just bought a new house home, want to invite a friend to celebrate, so it is necessary to hold a large dining table, dining table can accommodate the number of people equal to the circumference of the table, you want to buy a can accommodate up to people's dining table, side table must parallel with the side of the room.
To design your room, up to calculate the number of guests invited.
 

Input

The first line contains two integers R and C (1 <= R, C <= 2000), represented by the length and width of the house.
Next R S lines each character (no spaces), "." Indicates a blank area, "X" indicates an obstacle, the area occupied by the table must be empty.

Output

Output up to the required number of guests.
 

Sample Input

Input 1: 
22 
.. 
.. 

Input 2: 
. 4. 4 
X.XX 
X..X 
.. X-. 
..XX 

input. 3: 
. 3. 3 
XX 
. .X 
XX

Sample Output

Output 1: 
7 

Output 2: 
9 

output 3: 
3
 

Data Constraint

 
 

Hint

[Data size]
50% of the data is R & lt, C <400 =
70% of the data R & lt, C <1000 =
100% of the data, R, C <= 2000

 

analysis

 

  • In fact, the data can be too violent water
  • Set up [i] [j] is the i-th row and j grid up to find the most qualified
  • n3 violence
  • Or the stack can be monotonous

 

Code

 1 #include<iostream>
 2 using namespace std;
 3 int a[2001][2001],up[2001][2001],st[2001][2001];
 4 int main ()
 5 {
 6     int n,m;
 7     char c;
 8     cin>>n>>m;
 9     for (int i=1;i<=n;i++)
10     {
11         for (int j=1;j<=m;j++)
12         {
13             cin>>c;
14             if (c=='.')
15             {
16                 a[i][j]=1;
17                 up[i][j]=up[i-1][j]+1;
18             }
19             else a[i][j]=0;
20         }
21     }
22     int ans=0;
23     for (int i=1;i<=n;i++)
24     {
25         int top=0,w[55]={0},q[55]={0};
26         for (int j=1,h=0;j<=m+1;j++)
27         {
28             if (j!=m+1) h=up[i][j];
29             else h=0;
30             if (h>q[top])
31                q[++top]=h,w[top]=1;
32             else
33             {
34                 int cnt=0;
35                 while (h<=q[top]&&top>=1)
36                 {
37                     ans=max(ans,2*(w[top]+cnt)+2*q[top]);
38                     cnt+=w[top--];
39                 }
40                 if (j!=m+1&&a[i][j]!=0) q[++top]=h,w[top]=cnt+1;
41             }
42         }
43     }
44      cout << ans- 1 ;
45 }

 

Guess you like

Origin www.cnblogs.com/zjzjzj/p/11333016.html