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 ...
随机推荐
- VUE:Select2
<template> <div> <ul class="skill"> <li v-for='item of list' v-on:cli ...
- 【git】git中使用https和ssh协议的区别以及它们的用法
git可以使用四种主要的协议来传输资料: 本地协议(Local),HTTP 协议,SSH(Secure Shell)协议及 git 协议.其中,本地协议由于目前大都是进行远程开发和共享代码所以一般不常 ...
- 和PHP相关的Linux命令
Linux服务器上怎么找到php.ini php -ini #输出一堆信息,里面有loaded configuration file => /etc/php/7.0/cli/php.ini就是了 ...
- Java Spring MVC工作流程
本文是对 SpringMVC 工作流程的总结,自己一定要可以用语言描述. 名词解释: DispatcherServlet:前端控制器,是 SpringMVC 工作流程的中心,负责调用其他组件,在系统启 ...
- Verilog写入变量值到文件语句
integer signed fid_out1,fid_out2; initial begin fid_out1 = $fopen("dataout_i.txt","w& ...
- javascript面向对象 用new创建一个基于原型的javascript对象
//创建一个类 其实就是个对象 var Student={ name:"robot", height:1.6, run:function(){ console.log(this.n ...
- BDD行为驱动简介及Pytest-bdd基础使用
目录 BDD介绍 需求描述/用户场景 场景解析/实现 场景测试 Pytest-bdd的参数化 运行环境: pip insall pytest pytest-bdd pytest-selenium BD ...
- apidoc 接口文档系统
代码未动,文档先行.apidoc可以方便地维护接口文档.模拟响应数据.前后端分离.导出PDF文档. 特性说明 可视化编辑:支持表单界面编辑接口,不必手动编辑swagger.json 接口模拟响应:支持 ...
- LeetCode 200. 岛屿的个数(Number of Islands)
题目描述 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 1 ...
- centos7 python2升级python3
安装前的准备环境 yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurse ...