Rectangle
在 x 轴上有相互挨着的矩形, 这些矩形有一个边紧贴着 x 轴,现在给出每个矩形的长宽, 所有的矩形看作整体当作一个画布, 则可以在这个画布上画出的最大的矩形的面积是多少。(画出的矩形长和高平行于X,Y轴)
每组第一个数N(0<=N<=20000)表示N个矩形。下面N行有两个数a(1 <= a <=1000),b(1 <= b<=1000)分别表示每个矩形的x轴长度和y轴长度。
输出最大的面积。

#include <stdio.h>
long dynamicCaculate(int size);
long x_and_y[][] = {};
int main() {
int n;
scanf("%d", &n);
long i = ;
while (i < n) {
scanf("%d %d", &x_and_y[i][], &x_and_y[i][]);
i++;
}
long res = dynamicCaculate(n);
printf("%ld", res);
return ;
}
//分包不包括下一个输入的矩形
long dynamicCaculate(int size) {
if (size == ) {
return ;
}
long res_1 = ;
for (int i = ; i < size; ++i) {
long tempArea = ;
int totalWidth = x_and_y[i][];
for (int j = i - ; j >= ; --j) {
if (x_and_y[j][] >= x_and_y[i][]) {
totalWidth += x_and_y[j][];
} else {
break;
}
}
for (int j = i + ; j < size; ++j) {
if (x_and_y[j][] >= x_and_y[i][]) {
totalWidth += x_and_y[j][];
} else {
break;
}
}
tempArea = totalWidth * x_and_y[i][];
res_1 = res_1 > tempArea ? res_1 : tempArea;
}
return res_1;
}
Rectangle的更多相关文章
- [LeetCode] Perfect Rectangle 完美矩形
Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...
- [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
- [LeetCode] Smallest Rectangle Enclosing Black Pixels 包含黑像素的最小矩阵
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
- [LeetCode] Maximal Rectangle 最大矩形
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
- [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- Maximal Rectangle
很不好想的一道题,参考:http://blog.csdn.net/doc_sgl/article/details/11832965 分为两步:把原矩阵转为直方图,再用largest rectangle ...
- 85. Maximal Rectangle
85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...
- poj 2559 Largest Rectangle in a Histogram - 单调栈
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19782 ...
- LeetCode 笔记系列 17 Largest Rectangle in Histogram
题目: Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar he ...
随机推荐
- 洛谷P1020 导弹拦截【单调栈】
题目:https://www.luogu.org/problemnew/show/P1020 题意: 给定一些导弹的高度. 一个导弹系统只能拦截高度不增的一系列导弹,问如果只有一个系统最多能拦截多少导 ...
- 移动端H5开发问题记录
1. 当弹出键盘时,会改变页面高度,影响页面样式 通过window.onsize事件可以控制键盘弹出或消失的时候的样式 var h = document.body.scrollHeight // 用o ...
- yii框架学习(获取插入后的id)
插入单条数据, 获取插入数据的id. $model->attributes['id']; new model 添加数据的时候, 需要注意, 如果是想要循环添加多条数据的情况, new mode ...
- hover([over,]out)
hover([over,]out) 概述 一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法.这是一个自定义的方法,它为频繁使用的任务提供了一种“保持在其中”的状态. 当鼠标移动到一个匹配 ...
- Enable file editing in Visual Studio's debug mode
Visual Studio 使用及调试必知必会 http://www.cnblogs.com/luminji/p/3287728.html How do I enable file editing i ...
- 源码安装ROS Melodic Python3 指南 (转) + 安装记录
这篇文章转自 https://blog.csdn.net/id9502/article/details/80410989 csdn真是作大死,我保存这篇博客的时候还不需要花钱就能看,现在居然要v ...
- Django基础之template
1. 模板系统的介绍 def current_datetime(request): now = datetime.datetime.now() html = "<html>< ...
- JS判断开始时间不能大于检查结束时间
//用来检验检查开始时间不能大于检查结束时间 function checkDate(date){ var startDate = $("#jcrwModel_rwfqsj").va ...
- OC和Swift进行互相调用
swift调用oc的方法: 1.桥接文件,一般是swift工程,在创建一个oc文件时,系统自动添加(不用改名,直接默认即可) 2.将需要引用的oc文件 .h头文件 添加到桥接类中. 如下: 然后在sw ...
- 剑指offer21----数组中奇数偶数
题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分. 基本实现 如果不考虑时间复杂度,最简单的思路应该是从头扫描这个数组,每 ...