Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 911 Accepted Submission(s): 304 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.
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.
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
Recommend lcy
|
题目大意:某电影院有R排C列,然后有k个朋友去看电影,电影院还有些空座,然后求解他们k个人最后坐下的面积最小为多少,
思路:这个题目的话,首先要知道怎么统计某个矩形中的“.”的个数,也就是座位的个数,
这里就想到了我们概率论中那个划分概率区间的一个图了,下面画给大家
从上面的图中,我们可以看出,就是四个顶点的左上方的区域,然后做一个容斥,就得到了四个顶点中的面积,
我们这里的座位数目也是这个道理
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=400;
char st[maxn][maxn];
int sum[maxn][maxn];
int num[maxn][maxn];
int r,c,k;
int main()
{
while(scanf("%d%d%d",&r,&c,&k)!=EOF)
{
if(r==0&&c==0&&k==0)
break;
for(int i=1; i<=r; i++)
{
scanf("%s",st[i]+1);
for(int j=1; j<=c; j++)
{
if(st[i][j]=='.')
num[i][j]=1;
else
num[i][j]=0;
sum[i][j]=sum[i][j-1]+num[i][j];
}
}
for(int i=2; i<=r; i++)
for(int j=1; j<=c; j++)
sum[i][j]+=sum[i-1][j];
int ans=inf;
for(int i=1; i<=c; i++) //枚举第一条竖线
for(int j=i; j<=c; j++)//枚举第二条竖线
{
int sta=1; //对于横线的尺取
for(int t=1; t<=r; t++)
{
while(sum[t][j]-sum[t][i-1]-sum[sta-1][j]+sum[sta-1][i-1]>=k)
{
ans=min(ans,(j-i+1)*(t-sta+1));
sta++;
}
}
}
printf("%d\n",ans);
}
return 0;
}