Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 889    Accepted Submission(s): 290

Problem Description
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
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1934 1940 1936 1932 1933 
 
题目是要求最小的矩形面积,要求矩形区域内有足够k个人坐的座位,如此实际上就是求矩形的有效面积,先求二维前缀和,然后进行暴力,结果超时,毕竟四层循环,想到尺取,可是怎么移动横纵坐标,都移动?不可,会有遗漏的情况,可以只对一个坐标尺取,这里是保持行的范围不变,对列进行尺取。
代码:
#include <iostream>
#include <cstdio>
#define MAX 300
using namespace std;
int r,c,k;
int sum[MAX + ][MAX + ];
inline int get(int l1,int l2,int r1,int r2) {
return sum[l2][r2] - sum[l1 - ][r2] - sum[l2][r1 - ] + sum[l1 - ][r1 - ];
}
int main() {
while(~scanf("%d%d%d",&r,&c,&k) && r && c && k) {
int ans = r * c + ;
for(int i = ;i <= r;i ++) {
getchar();
for(int j = ;j <= c;j ++) {
char ch = getchar();
if(ch == '.') sum[i][j] = ;
else sum[i][j] = ;
sum[i][j] += sum[i - ][j] + sum[i][j - ] - sum[i - ][j - ];
}
}
for(int i = ;i <= r;i ++) {
for(int j = ;j <= r;j ++) {
int left = ,right = ;
while(right <= c && left <= right) {
if(get(i,j,left,right) < k) right ++;
else {
ans = min(ans,(j - i + ) * (right - left + ));
left ++;
}
}
}
}
printf("%d\n",ans);
}
}

最新文章

  1. Oracle 第一天
  2. 通过样式class 判断多个checkbox redio 是否都选中
  3. ural 1110,快速幂
  4. grunt下cssmin的配置参数
  5. 杀死MySQL的连接
  6. Delphi -- 创建 桌面、发送到...、快速启动栏、开始菜单、程序菜单、右键菜 单
  7. 入我新美大的Java后台开发面试题总结
  8. [ 面试没回答上的问题2]IOS上给body绑定click事件的bug
  9. firefox中遇到的offsetX的问题
  10. end to end testing
  11. SKU : Stock Keeping Unit
  12. Django启动报错笔记
  13. Day3 -4.9!受到毕设的突然袭击,一脸蒙蔽,学习暂时停止,明晚继续
  14. 【转】WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式
  15. pytest.7.常见套路
  16. FinalizableReference, FinalizablePhantomReference, FinalizableReferenceQueue
  17. linux中查看某个端口(port)
  18. eclipse debug 执行到断点处并没有停下,断点无效问题
  19. 关于对象的 width offsetwidth availWidth scrollHeight
  20. 不可不看!CSS3中三十一种选择器用法

热门文章

  1. python之路:进击的小白
  2. PHP用星号隐藏部份用户名、身份证、IP、手机号、邮箱等实例
  3. centos6 没有eth0网络
  4. css float 浮动是个混球
  5. python函数模拟mysql增删改查功能
  6. display:inline-block 间隙
  7. 高通平台Bootloader启动流程【转】
  8. maven项目在打war包时出现非法字符: &#39;\ufeff&#39; 解决方案
  9. ssh框架整合意义
  10. 对象存储API