HDU
来源:互联网 发布:吉林美术生分数算法 编辑:程序博客网 时间:2024/05/16 02:57
Finding Seats
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 720 Accepted Submission(s): 217
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
ACM South American Programming Contest 2007
题意: 给你一个r,c,k然后给你一个r*c的矩阵,其中’.’代表空座,’X’代表已占,让你求最小的矩阵面积使得矩阵中空座的个数大于等于k个,范围:
分析:一个很明确的思路就是枚举起点终点,并维护一个二维前缀和即可,但是究竟怎么枚举法呢,暴力的话
参考代码
#include<bits/stdc++.h>using namespace std;const int N = 1000;int pre[N][N];int get(int x1,int y1,int x2,int y2){ return pre[x2][y2] - pre[x1-1][y2] - pre[x2][y1-1]+pre[x1-1][y1-1];}int main(){ int r,c,k; while(cin>>r>>c>>k,r+c+k){ char ch; memset(pre,0,sizeof(pre)); for(int i = 1;i <= r;i++){ for(int j = 1;j <= c;j++){ cin>>ch; pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1] + ((ch == '.')?1:0); } } int ans = 1<<20; for(int i = 1;i <= r;i++){ for(int j = i;j <= r;j++){ int l,r; l = r = 1; while(true){ while(get(i,l,j,r) < k && r < c) r++; if(get(i,l,j,r) < k) break; if(get(i,l,j,r) >= k) { ans = min(ans,(r-l+1)*(j-i+1)); } l++; } } } cout<<ans<<endl; } return 0;}
- 如有错误或遗漏,请私聊下UP,thx
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 邮箱基础查询系统原型
- java语言程序程序设计 第十一章 (11.11、11.12、11.13、11.14、11.15、11.16、11.17)
- 2.磁盘挂载命令(mount)
- 只要程序员!杭州大妈冲进云栖大会为女儿征婚
- 还没对象吗?要不要给你介绍
- HDU
- 测试小故事43:视角
- Kotlin 将超越 Java 成为 Android 开发的第一语言?
- Java Development Kit 1.8下载
- 3.创建目录(mkdir)
- 【codevs 1961】躲避大龙
- 171014—表达式&运算符&相关
- git fatal: remote origin already exists.
- mysql 恢复删除数据