HDU 1937 f-finding Seats

Source: Internet
Author: User

f-finding seatsTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i6 4u Submit Status Practice HDU 1937

Description

A group of K friends is going to see a movie. However, they is too late to get good tickets, so they is looking for a good the-to-sit all nearby. Since They is all science students, they decided to come up with a optimization problem instead of going on with Informa L arguments to decide which tickets to buy.

The movie theater have 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 of the other are all this matters, even if that means seating in the front row where the S Creen is so big it's impossible to see it all at once. In order to has 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 so contains all bought s Eats. The area of a rectangle are the number of seats contained in it.

They ' ve taken out a laptop and pointed at the help them find those desired seats.

Input

Each test case would consist on several lines. The first line would contain three positive integers R, C and K as explained above (1 <= r,c <=, 1 <= K <= RXC). The next R lines would contain exactly C characters each. The j-th character of the i-th line would be ' X ' if the j-th seat on the i-th row was taken or '. ' If it is available. There always is at the least K available seats in total.
Input is terminated with R = C = K = 0.

Output

For each test case, the output a single line containing the minimum extension the group can has.

Sample Input

3 5 5...XX. X.xxxx ... 5 6 6..x.x. Xxx... Xx. X.. Xxx. x.xx. XX0 0 0

Sample Output

69
#include <stdio.h>#include<string.h>intmap[ -][ -];Charstr[ -][ -];inttmin,k;intCalculateintX1,intY1,intX2,inty2) {   intpoint=map[x1][y1]-map[x2-1][y1]-map[x1][y2-1]+map[x2-1][y2-1];//determine the number of vertices in this rangeintArea= (x1-x2+1) * (y1-y2+1);//Judging the area within this rangeif(point>=k&&area<tmin)//If the number of vertices is sufficient and the area can be reduced, the minimum value is updated tmin=Area ; returnPoint ;}intMain () {intx, y;  while(SCANF ("%d%d%d", &x,&y,&k)! =EOF) {        if(x==0&&y==0&&k==0)         Break; memset (str,0,sizeof(str)); memset (Map,0,sizeof(map));       GetChar ();  for(intI=1; i<=x;i++) {scanf ("%s", str[i]+1);          GetChar (); intsum=0;  for(intj=1; j<=y;j++){            if(str[i][j]=='.') Sum++; MAP[I][J]=map[i-1][j]+sum;//building a map array, similar to the idea of dynamic planning}} Tmin=1000000;  for(intx1=x;x1>=1; x1--) {//from bottom to topif(map[x1][y]<k) Break;  for(intX2=1; x2<=x1;x2++) {//from top to bottomif(map[x1][y]-map[x2-1][y]<k) Break; inty1=1, y2=1;  while(y1<=y&&y2<=y) {//Two vertices left to rightif(Calculate (X1,y1,x2,y2) >=k) Y2++; Else{                if(y1==y) Break; Y1++; } }}} printf ("%d\n", tmin); }   return 0;}


HDU 1937 f-finding Seats

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.