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,求满足这个条件的最小矩阵,也就是面积最小, 就这个意思,但是英语不好的我看了好久啊啊啊。。。。。英语重要啊!!!

题解: 先计算一下前缀和,然后用两把尺子开始找,就是用右下角的前缀和减去右上角的再减去左下角的再加上左上角的,不懂看图   

                 
                 
                 
                 
                 
                 
                 
                 
                 

就是蓝色减红色减黄色加绿色,为什么加绿色呢,因为绿色包含在红色和黄色里面,它被减了两次所以加一次。

请看代码:

 

#include <iostream>
using namespace std;
char map[400][400];
int a[400][400];
int main(){
	int r,c,k;
	while(cin >> r >> c >> k,r+c+k){
		for (int i = 1; i <= r;i++){// 输入
			scanf("%s",map[i]+1);
		}
		for (int i = 1; i <= r;i++){// 计算前缀和
			int x=0;
			for (int j = 1; j <= c; j++){
				if(map[i][j]=='.') x++;
				a[i][j]=a[i-1][j]+x;
			}
		}
		int minn;
		minn=999999999;
		for (int i = 1; i <= c;i++){// j与i为第一把尺子,量左右宽度;
			for (int j = i; j <= c;j++){
				int p=1;
				for (int w = 1; w <= r;w++){// p与w为第二把尺子,量上下长度
					while((a[w][j]-a[w][i-1]-a[p-1][j]+a[p-1][i-1])>=k){
						minn=min(minn,(w-p+1)*(j-i+1));// 每次记录一下符合条件的矩阵面积
						p++;
					}
				}
			}
		}
		cout << minn << endl;
	}
	return 0;
}