1. 程式人生 > >492 Construct the Rectangle給定矩形的面積計算符合要求的長和寬

492 Construct the Rectangle給定矩形的面積計算符合要求的長和寬

Problem:給定一個矩形的面積,求這個矩形的長和寬,使得長大於寬,長寬都是整數且差最小。
Solution:從根號下面積開始逐漸遞減,直到找到可整除的數。

class Solution {
public:
    vector<int> constructRectangle(int area) {
        int m=sqrt(area);
        vector<int> res;
        while(m>0){
            if(area%m==0){
                res.push_back(area/m); //長
res.push_back(m); //寬 break; } m--; } return res; } };

相關推薦

492 Construct the Rectangle給定矩形面積計算符合要求

Problem:給定一個矩形的面積,求這個矩形的長和寬,使得長大於寬,長寬都是整數且差最小。 Solution:從根號下面積開始逐漸遞減,直到找到可整除的數。 class Solution { public: vector<int>

492 Construct the Rectangle 構建矩形

details UC con rect csdn etc code SQ rec 詳見:https://leetcode.com/problems/construct-the-rectangle/description/ C++: class Solution { pub

leetcode-492-Construct the Rectangle

span 就是 developer 一個 con class mis 我們 限定 題目描述: For a web developer, it is very important to know how to design a web page‘s size. So, giv

[LeetCode&Python] Problem 492. Construct the Rectangle

For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now

Leetcode492.Construct the Rectangle構造矩形

作為一位web開發者, 懂得怎樣去規劃一個頁面的尺寸是很重要的。 現給定一個具體的矩形頁面面積,你的任務是設計一個長度為 L 和寬度為 W 且滿足以下要求的矩形的頁面。要求: 1. 你設計的矩形頁面必須等於給定的目標面積。 2. 寬度 W 不應大於長度 L,換言之,要求 L

[LeetCode] Construct the Rectangle 構建矩形

For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is t

Leetcode PHP題解--D111 492. Construct the Rectangle

D111 492. Construct the Rectangle 題目連結 492. Construct the Rectang

[LeetCode]223. Rectangle Area矩形面積

body post 一道 etc spa span 數據 max 溢出 /* 像是一道數據分析題 思路就是兩個矩形面積之和減去疊加面積之和 */ public int computeArea(int A, int B, int C, i

LeetCode-Construct the Rectangle

Description: For a web developer, it is very important to know how to design a web page’s size. So, g

Rectangle Area 矩形面積

在二維平面上計算出兩個由直線構成的矩形重疊後形成的總面積。 每個矩形由其左下頂點和右上頂點座標表示,如圖所示。 示例: 輸入: -3, 0, 3, 4, 0, -1, 9, 2 輸出: 45 說明: 假設矩形面積不會超出 int 的範圍。 思路

從鍵盤輸入矩形計算並輸出矩形的周長和麵積

//順序機構及流程  #include"stdio.h"                        &nb

定義一個類,封裝矩形;在定義一個類,繼承自定義的這個類,在繼承類中根據基類中封裝的矩形矩形面積

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 封裝長方體 {    

opencv 顯示最小面積的外接矩形,並求該矩形以及四個角的位置

#include "cv.h" #include "highgui.h" #include <stdio.h> #include <math.h> int main(int argc,char** argv) {  IplImage *src,*gr

【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest B】【暴力雙排序】Layer Cake 若干矩形 選擇相同的最大體積

Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and boughtnrectangular cake layers. The length and the width of t

定義一個長方形類並將求周長面積定義為成員方法實現求周長和麵積的動能(要求鍵盤錄入)

package org.westos_05_封裝和private; /*  * 定義一個學生類,提供成員變數姓名,和年齡 *  * 現在的寫法:需要將成員變數私有化,提供對外的公共訪問方法(也屬於成員方法) * */ class Student2{//私有化成員變數priv

已知一個抽象類Shapge,該類中有一個方法GetArea。 要求定義一個Rectangle類,繼承Shape類,實現GetArea方法計算矩形面積

已知一個抽象類Shapge,該類中有一個方法GetArea。 要求定義一個Rectangle類,繼承Shape類,實現GetArea方法計算矩形面積。 輸入輸出說明: 輸入: 5 4 輸

LeetCode 223. Rectangle Area(兩個矩形的複合面積計算

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top r

LeetCode 223 Rectangle Area(矩形面積

lee return common 分享 span spa class tracking mod 翻譯 找到在二維平面中兩個相交矩形的總面積。 每一個矩形都定義了其左下角和右上角的坐標。 (矩形例如以下圖) 如果,總占地面積永遠不會超過int

最大的矩形面積 Maximal Rectangle

htm public length for angle col ram com pub 2018-09-15 10:23:44 一、Largest Rectangle in Histogram 在求解最大的矩形面積之前,我們先討論一條最大直方圖面積的問題。 問題描述: 問

Leetcode 84. Largest Rectangle in Histogram 柱狀圖的最大矩形面積

解決思路:        問題主要考察每一根柱子最大能擴多大,這個行為的實質就是找到柱子左邊剛比它小的柱子的位置在哪裡,以及右邊剛比它小的柱子位置在哪裡,為了模擬這個過程,我們可以用棧模擬這個過程。        棧裡邊儲存的是一個遞增柱子的位置,每次遇到一個比棧頂位