F - Finding Seats

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 
 
 
#include<stdio.h>
#include<string.h>
int map[][];
char str[][];
int tmin,k;
int calculate(int x1,int y1,int x2,int y2){
int point=map[x1][y1]-map[x2-][y1]-map[x1][y2-]+map[x2-][y2-];//判断这一范围内的顶点数
int area=(x1-x2+)*(y1-y2+);//判断这一范围内的面积
if(point>=k&&area<tmin)//如果顶点数足够并且面积可以缩小,则更新最小值
tmin=area;
return point;
}
int main(){
int x,y;
while(scanf("%d%d%d",&x,&y,&k)!=EOF){
if(x==&&y==&&k==)
break;
memset(str,,sizeof(str));
memset(map,,sizeof(map));
getchar();
for(int i=;i<=x;i++){
scanf("%s",str[i]+);
getchar();
int sum=;
for(int j=;j<=y;j++){
if(str[i][j]=='.')
sum++;
map[i][j]=map[i-][j]+sum;//构建map数组,类似于动态规划的思想
}
}
tmin=;
for(int x1=x;x1>=;x1--){//从下到上
if(map[x1][y]<k)
break;
for(int x2=;x2<=x1;x2++){//从上到下
if(map[x1][y]-map[x2-][y]<k)
break;
int y1=,y2=;
while(y1<=y&&y2<=y){//两个顶点从左到右
if(calculate(x1,y1,x2,y2)>=k)
y2++; else{
if(y1==y)
break;
y1++;
}
}
}
} printf("%d\n",tmin);
}
return ;
}
 
 
 
 

HDU 1937 F - Finding Seats 枚举的更多相关文章

  1. hdu1937 Finding Seats

    hdu1937 Finding Seats 题意是 求最小的矩形覆盖面积内包含 k 个 空位置 枚举上下边界然后 双端队列 求 最小面积 #include <iostream> #incl ...

  2. 【数位DP】 HDU 4734 F(x)

    原题直通车:HDU 4734 F(x) 题意:F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1, 求0.....B中F[x]<=F[A ...

  3. hdu 1937 Finding Seats

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  4. HDU 5752 Sqrt Bo【枚举,大水题】

    Sqrt Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  5. hdu 5288 OO’s Sequence 枚举+二分

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  6. HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...

  7. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. HDU - 2802 F(N) (周期)

    题目链接:HDU 2009-4 Programming Contest 分析:具有一定的周期性——4018处理下就可以A了 Sample Input Sample Output AC代码: #incl ...

  9. 2017广东工业大学程序设计竞赛决赛 题解&源码(A,数学解方程,B,贪心博弈,C,递归,D,水,E,贪心,面试题,F,贪心,枚举,LCA,G,dp,记忆化搜索,H,思维题)

    心得: 这比赛真的是不要不要的,pending了一下午,也不知道对错,直接做过去就是了,也没有管太多! Problem A: 两只老虎 Description 来,我们先来放松下,听听儿歌,一起“唱” ...

随机推荐

  1. 2、SpringBoot+Mybatis整合------一对一

    开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/SpringBoot_Mybatis01/tree/93398da60c647573645917b2 ...

  2. 【赛时总结】 ◇赛时·IV◇ CODE FESTIVAL 2017 Final

    ◇赛时-IV◇ CODE FESTIVAL 2017 Final □唠叨□ ①--浓浓的 Festival 气氛 ②看到这个比赛比较特别,我就看了一看--看到粉粉的界面突然开心,所以就做了一下 `(* ...

  3. SpringMVC使用ModelAndView的相对路径和绝对路径的问题

    例如:abc/a/a.jsp,想要跳转到根目录的b.jsp 使用 ModelAndView 跳转, 若引用:org.springframework.web.portlet.ModelAndView 这 ...

  4. IO流的应用_Copy文件

    IO流的应用_Copy文件 (1) import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundEx ...

  5. Xtrabackup实现MySQL备份

    一.xtrabackup介绍 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写)它由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上 ...

  6. 用js控制单选框或者多选框问题

    出现如图问题时,这时不能用attr方法添加checked属性了,改用$( "input" ).prop( "checked", true ),完美解决.

  7. 控制器方法重复命名导致nginx 504的问题

    由于控制器方法重复命名重启swoole后运行代码导致 504 Gateway Time-out ,查看laravel日志和nginx日志才找原因所在,以后还是要多看错误日志.

  8. 【JavaScript】jQuery绑定事件

    jquery中直接绑定事件:只能用在程序中一开始就存在的html代码 目标元素.click(function(){ }) jquery中间接绑定事件: 如果目标元素是js生成的,则需要间接绑定事件,用 ...

  9. SQL_server_2008_r2和visual studio 2010旗舰版的安装(2013-01-16-bd 写的日志迁移

    (以下操作是在Oracle VM virtualBox虚拟机中操作的,其实VMware Workstation 9虚拟机也挺不错的,不过用了很久的vmware想换个虚拟机用用 就暂时用Oracle V ...

  10. C语言进阶—— 逻辑运算符分析15

    印象中的逻辑运算符: ---学生:老师,在我的印象中,逻辑运算符用在条件判断的时候,真挺简单的,还有必要深究吗? ---老师:逻辑运算符确实在条件判断的时候用的比较多,但是并不能说简单... 请思考下 ...