【HDU - 1937 】Finding Seats(二维前缀和+尺取法)

题干:

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

题目大意:

让你找到最小的矩形体积,满足在他范围内存在至少k个 ' . '

解题报告:

    这题思路比较诡异。

AC代码:

#include<bits/stdc++.h>using namespace std;
const int INF =0x3f3f3f3f;
int minn;
char tmp[1000 + 5][1000 + 5];
int maze[1000 + 5][1000 + 5];
int main()
{int r,c,k;while(~scanf("%d%d%d",&r,&c,&k) ) {if(r+c+k == 0) break;memset(maze,0 ,sizeof(maze));minn = INF;for(int i = 1; i<=r; i++) {scanf("%s",tmp[i]+1);}for(int i = 1; i<=r; i++) {for(int j = 1; j<=c; j++) {tmp[i][j] == '.' ? maze[i][j] = 1 : maze[i][j] = 0;}}
//		for(int i = 1; i<=r; i++) {
//			for(int j = 1; j<=c; j++) {
//				printf("%d",maze[i][j]);
//			}
//			cout<<endl;
//		}for(int i = 1; i<=r; i++) {for(int j = 1; j<=c; j++) {maze[i][j] = maze[i][j] + maze[i-1][j] + maze[i][j-1] - maze[i-1][j-1];}}
//		for(int i = 1; i<=r; i++) {
//			for(int j = 1; j<=c; j++) {
//				printf("%d",maze[i][j]);
//			}
//			cout<<endl;
//		}int ll,rr;for(int i = 1; i <= r; i++)for(int j = i; j <= r; j++) {ll = 1; rr = 1;while(ll<=c && rr <=c) {while(maze[j][rr] - maze[j][ll-1] - maze[i-1][rr] + maze[i-1][ll-1]>=k && ll<=rr) {minn = min(minn,(j-i+1)*(rr-ll+1) );ll++;}rr++;}}printf("%d\n",minn);}return 0 ;
}

 总结:

      这道题难度也不能说大吧但是比较综合,这年头o(n^3)的方法基本不敢想。两个小地方出了错一个是二维前缀和的处理上写成了maze[i][j] = maze[i][j] - maze[i-1][j] - maze[i][j-1] + maze[i-1][j-1];  第二个错是在第二个while里面应该先更新minn再ll++,而不是先ll++再更新minn。

      把符合要求的点抽象成1,不符合的抽象成0,这一技巧貌似很常用?

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/439316.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【POJ - 1459】Power Network(网络流最大流,建图)

题干&#xff1a; A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) > 0 of power, may produce an amount 0 < p(u) < p max(u) of power, may …

【转】React Vue MVC MVVM MVP

首先&#xff0c;在谈这个话题之前&#xff0c; 我们有必要了解一下库和框架的区别。 我们先来看react官网以及vue官网对他们的定位&#xff1a; react: vue: react我们不说了&#xff0c;官网上明明白白说了&#xff0c;人家是一个library&#xff0c;用于构建用户界面。 v…

**【POJ - 3122】 Pie(二分寻值)

题干&#xff1a; My birthday is coming up and traditionally Im serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should b…

【转】IsCallBack属性和IsPostBack属性有什么区别?

if (Page.IsCallback) return; 此句话在page的构造函数中使用&#xff0c;不让page反复生成。比如一个TEXTbox如果不组织页面刷新&#xff0c;其数据会丢失。 以postback方式进行客户端和服务器端的交互的&#xff0c; IsPostBack就是true。 以callback方式进行客户端和服务器…

【转】使用Feature导入WebPart

原文链接&#xff1a;http://www.cnblogs.com/glife/archive/2009/10/27/1590488.html 前些天在刚刚接触WebPart的时候&#xff0c;搜到了一篇《使用Feature导入WebPart》的文章&#xff0c;那个时候对Feature的了解还为零&#xff0c;所以看了是一知半解&#xff0c;等到今天…

【HDU - 5017】Ellipsoid(爬山算法,模拟退火,三分)

题干&#xff1a; Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distance between the original point (0,0,0) and points on the ellipsoid. The distance between two points (x 1,y 1,z 1) and (x 2,y 2,z 2) is defined as Input There a…

【转】[SharePoint 开发详解] 一个Feature中使用SPGridView的几个Tips

根据上面一篇随笔所介绍的PC购买流程的项目&#xff0c;在项目中&#xff0c;需要有一个生成订单的功能&#xff0c;能够使得Admin很方便的在获得批准的申请中选取一些来生成订单&#xff0c;要求界面操作简单明了&#xff0c;大概的效果图如下&#xff1a; 点击checkbox&#…

【LeetCode - 131】分割回文串(dp,dfs)

题目链接&#xff1a;https://leetcode-cn.com/problems/palindrome-partitioning/ 题目&#xff1a; 给定一个字符串 s&#xff0c;将 s 分割成一些子串&#xff0c;使每个子串都是回文串。 返回 s 所有可能的分割方案。 示例: 输入: "aab" 输出: [ ["a…

【转】VSTS中版本控制系统Git与TFVC的区别

VSTS&#xff08;Visual Studio Team Services&#xff09; VSTS简单说就是微软TFS(Team Foundation Services)的升级云版&#xff0c;不用像TFS需要在企业内部服务器上部署&#xff0c;并且是免费提供给用户使用的。 每个有微软账号&#xff08;也是免费注册的&#xff09;的…

【LeetCode - 1254】统计封闭岛屿的数目(dfs,连通块)

题目链接&#xff1a;https://leetcode-cn.com/problems/number-of-closed-islands/ 有一个二维矩阵 grid &#xff0c;每个位置要么是陆地&#xff08;记号为 0 &#xff09;要么是水域&#xff08;记号为 1 &#xff09;。 我们从一块陆地出发&#xff0c;每次可以往上下左…

【转】0.SharePoint服务器端对象模型 之 序言

对于刚刚开始接触SharePoint的开发人员&#xff0c;即使之前有较为丰富的ASP.NET开发经验&#xff0c;在面对SharePoint时候可能也很难找到入手的方向。对于任何一种开发平台而言&#xff0c;学习开发的过程大致会包括&#xff1a;开发工具的使用、开发手段的选择和开发语言的编…

【LeetCode - 122】买卖股票的最佳时机 II(贪心 或 dp)

题目链接&#xff1a;https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/ 给定一个数组&#xff0c;它的第 i 个元素是一支给定股票第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易&#xff08;多次买卖一支股票…

【转】1.SharePoint服务器端对象模型 之 对象模型概述(Part 1)

在一个传统的ASP.NET开发过程中&#xff0c;我们往往会把开发分为界面展现层、逻辑业务层和数据访问层这三个层面。作为一个应用开发平台&#xff0c;SharePoint是微软在直观的开发能力和自由的扩展能力之间&#xff0c;取到的一个平衡点&#xff0c;其对象模型的设计理念也反映…

【LeetCode - 123】买卖股票的最佳时机 III

题目链接&#xff1a; 给定一个数组&#xff0c;它的第 i 个元素是一支给定的股票在第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你最多可以完成 两笔 交易。 注意&#xff1a;你不能同时参与多笔交易&#xff08;你必须在再次购买前出售掉之前的股票&#xf…

【转】1.2SharePoint服务器端对象模型 之 对象模型概述(Part 2)

&#xff08;三&#xff09;Url 作为一个B/S体系&#xff0c;在SharePoint的属性、方法参数和返回值中&#xff0c;大量的涉及到了Url&#xff0c;总的来说&#xff0c;涉及到的Url可以分为如下四类&#xff1a; 绝对路径&#xff1a;完整的Url&#xff0c;包含了协议头&…

【LeetCode - 224】基本计算器(栈)

实现一个基本的计算器来计算一个简单的字符串表达式 s 的值。 题目链接&#xff1a;https://leetcode-cn.com/problems/basic-calculator/ 示例 1&#xff1a; 输入&#xff1a;s "1 1" 输出&#xff1a;2 示例 2&#xff1a; 输入&#xff1a;s " 2-1 …

【转】2.1 SharePoint服务器端对象模型 之 访问网站和列表数据(Part 1)

本节将会介绍SharePoint中最为常用的一些对象模型&#xff0c;以及如何使用这些对象模型来访问和操作网站中的数据。几乎所有的SharePoint服务器端开发都会涉及到这些内容&#xff0c;因此应着重掌握本节中所介绍的基本对象模型的使用方法。由于篇幅所限&#xff0c;在介绍每种…

【LeetCode - 1047】删除字符串中的所有相邻重复项(栈)

https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/ 给出由小写字母组成的字符串 S&#xff0c;重复项删除操作会选择两个相邻且相同的字母&#xff0c;并删除它们。 在 S 上反复执行重复项删除操作&#xff0c;直到无法继续删除。 在完成所有重复…

【转】2.2 SharePoint服务器端对象模型 之 访问网站和列表数据(Part 2)

&#xff08;二&#xff09;列表&#xff08;SPList&#xff09; 列表是SharePoint中最为重要的数据容器&#xff0c;我们一般保存在SharePoint中的所有数据&#xff0c;都是保存在列表中&#xff08;文档库也是一种列表&#xff09;&#xff0c;因此列表对象在SharePoint的开…

【LeetCode - 227】基本计算器 II(栈)

https://leetcode-cn.com/problems/basic-calculator-ii/ 给你一个字符串表达式 s &#xff0c;请你实现一个基本计算器来计算并返回它的值。 整数除法仅保留整数部分。 示例 1&#xff1a; 输入&#xff1a;s "32*2" 输出&#xff1a;7 示例 2&#xff1a; 输入…