题干:

A group of K friends is going to see a movie. However, they are too late to get good tickets, so they are looking for a good way to sit all nearby. Since they are all science students, they decided to come up with an optimization problem instead of going on with informal arguments to decide which tickets to buy. 

The movie theater has R rows of C seats each, and they can see a map with the currently available seats marked. They decided that seating close to each other is all that matters, even if that means seating in the front row where the screen is so big it’s impossible to see it all at once. In order to have a formal criteria, they thought they would buy seats in order to minimize the extension of their group. 

The extension is defined as the area of the smallest rectangle with sides parallel to the seats that contains all bought seats. The area of a rectangle is the number of seats contained in it. 

They’ve taken out a laptop and pointed at you to help them find those desired seats. 

Input

Each test case will consist on several lines. The first line will contain three positive integers R, C and K as explained above (1 <= R,C <= 300, 1 <= K <= R × C). The next R lines will contain exactly C characters each. The j-th character of the i-th line will be ‘X’ if the j-th seat on the i-th row is taken or ‘.’ if it is available. There will always be at least K available seats in total. 
Input is terminated with R = C = K = 0. 

Output

For each test case, output a single line containing the minimum extension the group can have.

Sample Input

3 5 5
...XX
.X.XX
XX...
5 6 6
..X.X.
.XXX..
.XX.X.
.XXX.X
.XX.XX
0 0 0

Sample Output

6
9

题目大意:

让你找到最小的矩形体积,满足在他范围内存在至少k个 ' . '

解题报告:

    这题思路比较诡异。

AC代码:

#include<bits/stdc++.h>

using namespace std;
const int INF =0x3f3f3f3f;
int minn;
char tmp[1000 + 5][1000 + 5];
int maze[1000 + 5][1000 + 5];
int main()
{
int r,c,k;
while(~scanf("%d%d%d",&r,&c,&k) ) {
if(r+c+k == 0) break;
memset(maze,0 ,sizeof(maze));
minn = INF;
for(int i = 1; i<=r; i++) {
scanf("%s",tmp[i]+1);
}
for(int i = 1; i<=r; i++) {
for(int j = 1; j<=c; j++) {
tmp[i][j] == '.' ? maze[i][j] = 1 : maze[i][j] = 0;
}
}
// for(int i = 1; i<=r; i++) {
// for(int j = 1; j<=c; j++) {
// printf("%d",maze[i][j]);
// }
// cout<<endl;
// }
for(int i = 1; i<=r; i++) {
for(int j = 1; j<=c; j++) {
maze[i][j] = maze[i][j] + maze[i-1][j] + maze[i][j-1] - maze[i-1][j-1];
}
}
// for(int i = 1; i<=r; i++) {
// for(int j = 1; j<=c; j++) {
// printf("%d",maze[i][j]);
// }
// cout<<endl;
// }
int ll,rr;
for(int i = 1; i <= r; i++)
for(int j = i; j <= r; j++) {
ll = 1; rr = 1;
while(ll<=c && rr <=c) {
while(maze[j][rr] - maze[j][ll-1] - maze[i-1][rr] + maze[i-1][ll-1]>=k && ll<=rr) {
minn = min(minn,(j-i+1)*(rr-ll+1) );
ll++;
}
rr++;
}
}
printf("%d\n",minn);

}

return 0 ;
}

 总结:

      这道题难度也不能说大吧但是比较综合,这年头o(n^3)的方法基本不敢想。两个小地方出了错一个是二维前缀和的处理上写成了maze[i][j] = maze[i][j] - maze[i-1][j] - maze[i][j-1] + maze[i-1][j-1];  第二个错是在第二个while里面应该先更新minn再ll++,而不是先ll++再更新minn。

      把符合要求的点抽象成1,不符合的抽象成0,这一技巧貌似很常用?