【HDU

编程入门 行业动态 更新时间:2024-10-12 01:23:28

【<a href=https://www.elefans.com/category/jswz/34/1769149.html style=HDU"/>

【HDU

题目:

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;
}

 

更多推荐

【HDU

本文发布于:2024-03-04 01:15:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1707868.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HDU

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!