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 ...
 
随机推荐
- Java对象间的关系
			
1 综述 在Java中对象与对象的关系总体分为四类,分别是:依赖.关联.聚合和组合. (1)依赖(Dependency)关系是类与类之间的联接.依赖关系表示一个类依赖于另一个类的定义,一般而言,依赖关 ...
 - offset([coordinates])
			
offset([coordinates]) 概述 获取匹配元素在当前视口的相对偏移. 返回的对象包含两个整型属性:top 和 left,以像素计.此方法只对可见元素有效.大理石平台价格表 参数 coo ...
 - SQL Server 基础:朝花夕拾
			
序言 INSERT INTO SELECT 与 SELECT INTO 通俗来讲,INSERT INTO SELECT 和 SELECT INTO 两个语句的作用都是复制表,因为都是从一个表中查询出数 ...
 - Python数据抓取(1) —数据处理前的准备
			
(一)数据抓取概要 为什么要学会抓取网络数据? 对公司或对自己有价值的数据,80%都不在本地的数据库,它们都散落在广大的网络数据,这些数据通常都伴随着网页的形式呈现,这样的数据我们称为非结构化数据 如 ...
 - IDEA checkout Git 分支 弹出 Git Checkout Problem
			
1. 本地分支切换的时候(例如A切到B),会弹出来Restore workspace on branch switching 对话框,如果选择是的话,在切换分支的时候,你在当前分支(A)所做的一些还未 ...
 - 【Spring Boot】 Spring Boot 2.x 版本 CacheManager 配置方式
			
Spring Boot 1.X RedisCacheManager 配置方式 @Bean public CacheManager cacheManager(RedisTemplate redisTem ...
 - Leetcode题目152.乘积最大子序列(动态规划-中等)
			
题目描述: 给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数). 示例 1: 输入: [2,3,-2,4] 输出: 6 解释: 子数组 [2,3] 有最大乘积 6 ...
 - 如何选CDN:互联网大直播时代的CDN选择指南
			
转: 如何选CDN:互联网大直播时代的CDN选择指南 from: http://www.chnvideo.com/blog-classic-cdn.html SRS 编码器 如何选CDN:互联网 ...
 - ARP 之 发送请求arp_solicit
			
概述 arp_solicit用来发送ARP请求,首先会根据ARP_ANNOUNCE参数来选取源地址,然后判断是否达到内核发送次数上限,未达到则调用内核arp_send_dst函数发送,如果达到上限,则 ...
 - Docker搭建ELK分析tomat日志
			
最近公司的项目中用到了ELK,正好有时间自己搭建一个学习一下.在实体机或虚拟机中搭建还需要安装软件,使用docker镜像安装是省时省力的,如下是步骤. 1. 下载elasticsearch镜像: #d ...