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. cudpp库使用说明

    所有信息是我个人在使用过程中的小小经验,不是什么权威性文档,旨在帮助需要研究此类信息的朋友少走点弯路. 整个项目的主函数,一切从这里开始 在cudpp_testrig右键属性页里找到调试,在命令行里输 ...

  2. JS中的执行环境和作用域

    window 是最大最外围的执行环境,然后每个函数都有自己的执行环境.JS代码是从上到下执行的,单纯的用语言描述可能会有点绕,而且不大直观.我们看着代码来 console.log('global be ...

  3. 6、SpringBoot+Mybatis整合------参数传递

    开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/SpringBoot_Mybatis/tree/7892801d804d2060774f3720f8 ...

  4. Spring详解篇之 AOP面向切面编程

    一.概述 Aop(aspect oriented programming面向切面编程),是spring框架的另一个特征.AOP包括切面.连接点.通知(advice).切入点(pointCut) . 1 ...

  5. 【Java】异常 —— throw, throws, try catch 相关内容

    嗯……面试考到了这个,又是一个如无意外 那么接下来就总结吧 一.什么是异常 程序运行过程中发生的异常事件. RuntimeException通常是因为编程员因为疏忽没有检查而引起的错误. 二.Exce ...

  6. Angular/cli的安装

    Angular cli 是一个命令行工具,用来创建,打包,发布项目. Angular cli 安装之前必须先安装Node 6.9.0及以上版本,NPM 3 及以上版本. 在cmd控制台窗口执行命令no ...

  7. jquery 操作css 选择器

    .addClass() 为每个匹配的元素添加指定的样式类名 .addClass(className) className 为每个匹配元素所有增加的一个或多个样式名 .addClass(function ...

  8. Spring Cloud 入门 Consul-Client服务提供

    前面介绍了 Rureka Client服务提供, 只需要改pom.xml部分内容 1.pom.xml <?xml version="1.0" encoding="U ...

  9. 图解HTTP总结(5)——与HTTP协作的Web服务器

    一台 Web 服务器可搭建多个独立域名的 Web 网站, 也可作为通信路径上的中转服务器提升传输效率. 用单台虚拟主机实现多个域名 HTTP/1.1 规范允许一台 HTTP 服务器搭建多个 Web 站 ...

  10. 779. K-th Symbol in Grammar

    class Solution { public: int kthGrammar(int N, int K) { return helper(N, K, false); } int helper(int ...