HDU 1937 F - Finding Seats 枚举
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
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
Sample Input
...XX
.X.XX
XX...
5 6 6
..X.X.
.XXX..
.XX.X.
.XXX.X
.XX.XX
0 0 0
Sample Output
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 枚举的更多相关文章
- hdu1937 Finding Seats
hdu1937 Finding Seats 题意是 求最小的矩形覆盖面积内包含 k 个 空位置 枚举上下边界然后 双端队列 求 最小面积 #include <iostream> #incl ...
- 【数位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 ...
- hdu 1937 Finding Seats
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- HDU 5752 Sqrt Bo【枚举,大水题】
Sqrt Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- 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 ...
- 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的时候的个数,然后需要预处理下小 ...
- HDU 2802 F(N)(简单题,找循环解)
题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU - 2802 F(N) (周期)
题目链接:HDU 2009-4 Programming Contest 分析:具有一定的周期性——4018处理下就可以A了 Sample Input Sample Output AC代码: #incl ...
- 2017广东工业大学程序设计竞赛决赛 题解&源码(A,数学解方程,B,贪心博弈,C,递归,D,水,E,贪心,面试题,F,贪心,枚举,LCA,G,dp,记忆化搜索,H,思维题)
心得: 这比赛真的是不要不要的,pending了一下午,也不知道对错,直接做过去就是了,也没有管太多! Problem A: 两只老虎 Description 来,我们先来放松下,听听儿歌,一起“唱” ...
随机推荐
- Win7多用户同时登陆
软件提供下载: http://pan.baidu.com/s/1o6FQv70
- Laplace算子和Laplacian矩阵
1 Laplace算子的物理意义 Laplace算子的定义为梯度的散度. 在Cartesian坐标系下也可表示为: 或者,它是Hessian矩阵的迹: 以热传导方程为例,因为热流与温度的梯度成正比,那 ...
- fine ui grid控件添加行号
grid控件的列中添加如下代码<f:RowNumberField EnablePagingNumber="true" TextAlign="Center" ...
- java TCP通信 socket 套接字 用图片上传轰炸服务器
客户端 package com.swift.jinji; import java.io.FileInputStream; import java.io.IOException; import java ...
- 微信小程序开发踩坑与总结 -
原文链接:https://segmentfault.com/a/1190000008516296 前段时间把公司小程序项目开发完成了,所以来写写自己开发过程中碰到的问题和解决方法,以及用到的提高效率的 ...
- ssm整合-错误3
1.警告: Unknown version string [3.1]. Default version will be used. 因为Tomcat版本为7,支持3.1版本的为Tomcat 8: 2. ...
- Linux文件服务器实战(匿名用户)
一.进程与线程 二.vsftp服务器 1.文件传输协议(file transfer protocol,FTP) 基于该协议ftp客户端和服务端实现文件共享,上传下载文件 FTP基于TCP协议生成一个虚 ...
- 路由器基础配置之rip
我们将以上面的拓扑图进行实验,用rip协议来进行实验,目的是实现三台不同网段的pc机之间实现互相通信 首先为pc机配置好ip地址和网关,配置完IP地址后在配置路由器 router1: enable 进 ...
- 用ajax获取淘宝关键字接口
可定需要查看淘宝界面的结构,按F12查看网页,此时先清除一下网页中的数据,让Network制空,随后在输入框中输入新的内容,比如钱包,数据中会出现新的数据.点击及查看蓝色方框中的内容 点击之后,你可以 ...
- 【转载】谈MongoDB的应用场景
引用:http://blog.csdn.net/adparking/article/details/38727911 MongoDB的应用场景在网上搜索了下,很少介绍关于传统的信息化应用中如何使用Mo ...