题目描述

在 x 轴上有相互挨着的矩形, 这些矩形有一个边紧贴着 x 轴,现在给出每个矩形的长宽, 所有的矩形看作整体当作一个画布, 则可以在这个画布上画出的最大的矩形的面积是多少。(画出的矩形长和高平行于X,Y轴)

解答要求时间限制:3000ms, 内存限制:64MB
输入

每组第一个数N(0<=N<=20000)表示N个矩形。下面N行有两个数a(1 <= a <=1000),b(1 <= b<=1000)分别表示每个矩形的x轴长度和y轴长度。

输出

输出最大的面积。

  1. #include <stdio.h>
  2.  
  3. long dynamicCaculate(int size);
  4.  
  5. long x_and_y[][] = {};
  6.  
  7. int main() {
  8. int n;
  9. scanf("%d", &n);
  10. long i = ;
  11. while (i < n) {
  12. scanf("%d %d", &x_and_y[i][], &x_and_y[i][]);
  13. i++;
  14. }
  15. long res = dynamicCaculate(n);
  16. printf("%ld", res);
  17. return ;
  18. }
  19.  
  20. //分包不包括下一个输入的矩形
  21. long dynamicCaculate(int size) {
  22. if (size == ) {
  23. return ;
  24. }
  25. long res_1 = ;
  26. for (int i = ; i < size; ++i) {
  27. long tempArea = ;
  28. int totalWidth = x_and_y[i][];
  29. for (int j = i - ; j >= ; --j) {
  30. if (x_and_y[j][] >= x_and_y[i][]) {
  31. totalWidth += x_and_y[j][];
  32. } else {
  33. break;
  34. }
  35. }
  36. for (int j = i + ; j < size; ++j) {
  37. if (x_and_y[j][] >= x_and_y[i][]) {
  38. totalWidth += x_and_y[j][];
  39. } else {
  40. break;
  41. }
  42. }
  43. tempArea = totalWidth * x_and_y[i][];
  44. res_1 = res_1 > tempArea ? res_1 : tempArea;
  45. }
  46. return res_1;
  47. }

Rectangle的更多相关文章

  1. [LeetCode] Perfect Rectangle 完美矩形

    Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...

  2. [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 ...

  3. [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 ...

  4. [LeetCode] Rectangle Area 矩形面积

    Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...

  5. [LeetCode] Maximal Rectangle 最大矩形

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  6. [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  7. Maximal Rectangle

    很不好想的一道题,参考:http://blog.csdn.net/doc_sgl/article/details/11832965 分为两步:把原矩阵转为直方图,再用largest rectangle ...

  8. 85. Maximal Rectangle

    85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...

  9. poj 2559 Largest Rectangle in a Histogram - 单调栈

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19782 ...

  10. LeetCode 笔记系列 17 Largest Rectangle in Histogram

    题目: Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar he ...

随机推荐

  1. VUE:Select2

    <template> <div> <ul class="skill"> <li v-for='item of list' v-on:cli ...

  2. 【git】git中使用https和ssh协议的区别以及它们的用法

    git可以使用四种主要的协议来传输资料: 本地协议(Local),HTTP 协议,SSH(Secure Shell)协议及 git 协议.其中,本地协议由于目前大都是进行远程开发和共享代码所以一般不常 ...

  3. 和PHP相关的Linux命令

    Linux服务器上怎么找到php.ini php -ini #输出一堆信息,里面有loaded configuration file => /etc/php/7.0/cli/php.ini就是了 ...

  4. Java Spring MVC工作流程

    本文是对 SpringMVC 工作流程的总结,自己一定要可以用语言描述. 名词解释: DispatcherServlet:前端控制器,是 SpringMVC 工作流程的中心,负责调用其他组件,在系统启 ...

  5. Verilog写入变量值到文件语句

    integer signed fid_out1,fid_out2; initial begin fid_out1 = $fopen("dataout_i.txt","w& ...

  6. javascript面向对象 用new创建一个基于原型的javascript对象

    //创建一个类 其实就是个对象 var Student={ name:"robot", height:1.6, run:function(){ console.log(this.n ...

  7. BDD行为驱动简介及Pytest-bdd基础使用

    目录 BDD介绍 需求描述/用户场景 场景解析/实现 场景测试 Pytest-bdd的参数化 运行环境: pip insall pytest pytest-bdd pytest-selenium BD ...

  8. apidoc 接口文档系统

    代码未动,文档先行.apidoc可以方便地维护接口文档.模拟响应数据.前后端分离.导出PDF文档. 特性说明 可视化编辑:支持表单界面编辑接口,不必手动编辑swagger.json 接口模拟响应:支持 ...

  9. LeetCode 200. 岛屿的个数(Number of Islands)

    题目描述 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 1 ...

  10. centos7 python2升级python3

    安装前的准备环境 yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurse ...