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. 旧文备份:对象字典0x1005和0x1006的理解

    SYNC不一定由主站产生,因此,产生SYNC的节点,0x1005对象的值一般是0x40000080,第30位为1表示本节点产生 SYNC,而本节点的0x1006对象就是产生同步周期值了;而接收SYNC ...

  2. 《C++总结3》

    派生类 Class student1:public student   //表示公用继承,默认为私有的 {  public : …… …… } 继承的时候一定是全部继承来,但是可以自己设定访问属性,或 ...

  3. 路由传参,path和query的刷新报错js文件丢失

    日常的路由跳转,基本都会用到传参,有两种方式:path + query, name + params 常用的写法: this.$router.push({ path: 'proDetail',quer ...

  4. POJ1286 Necklace of Beads(Polya定理)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9359   Accepted: 3862 Description Beads ...

  5. motto - Express 4.x Request对象获得参数方法

    本文搜索关键字:motto express node js nodejs javascript request body request.body 1. req.param() 该方法获得参数最为方便 ...

  6. Apache POI 工具类 [ PoiUtil ]

    pom.xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml ...

  7. JAVAOOP集合框架

    集合框架三大内容:对外的接口.接口的实现和对集合运算的算法 集合有三大类接口:List.Set.Map 共同点:都是集合接口,都可以用来存储很多对象 不同:Collection接口存储一组不唯一(允许 ...

  8. laravel环境配置的常见问题

    从开始下载相关软件到现在,整整一天,终于成功了.不得不说官方的说明文档相当详细,毕竟我都成功了,不是吗,哈哈. 好了,不多说了,直接上干货 官方环境配置文档地址:https://laravel-chi ...

  9. 生产-消费模式的synchronized和lock实现(十)

    lock: package com.net.thread.lock; import java.util.concurrent.locks.Condition; import java.util.con ...

  10. 适合pc端的移动拖拽,分享一下。

    h5新加的特性拖拽事件,但是只适合PC端哦.不多说了上代码 <!DOCTYPE html> <html> <head> <title></titl ...