题目:
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
题意:某电影院有R排C列,然后有k个朋友去看电影,电影院还有些空座,然后求解他们k个人最后坐下的面积最小为多少,(四个角围成的矩形)
解题思路:转化一下思路,求解在一个面积内有多少空座,提前计算好,到时候直接做差就好,因为套四重循环会炸,所以用到了一步尺取,之后就是求面积的权值就好了。
ac代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define PI acos(-1.0)
#define maxn 355
#define eps 1e-8
using namespace std;
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=9999999;
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;
}
博客围绕一群朋友去电影院选座的优化问题展开。已知电影院有R排C列座位,朋友有K人,要使他们所坐区域的最小矩形面积(即扩展)最小。介绍了输入输出格式,给出解题思路,通过提前计算空座数量、运用尺取法求面积权值来求解。

144

被折叠的 条评论
为什么被折叠?



