Question

02. For a web developer, it is very important to know how to design a web page's size. So, given ...

02. 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 to design a rectangular web page, whose length L and width W satisfy the following requirements:

1. The area of the rectangular web page you designed must equal to the given target area.

2. The width W should not be larger than the length L, which means L >= W.

3. The difference between length L and width W should be as small as possible.

You need to output the length L and the width W of the web page you designed in sequence.

Example:

Input: 4

Output: [2, 2]

Explanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1].

But according to requirement 2, [1,4] is illegal; according to requirement 3, [4,1] is not optimal compared to [2,2]. So the length L is 2, and the width W is 2.

Note:

The given area won't exceed 10,000,000 and is a positive integer

The web page's width and length you designed must be positive integers.

class Solution {

public:

    vector<int> constructRectangle(int area) {

       

    }

};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Solution {

public:

vector<int> constructRectangle(int area) {

int height , width;

for (int i = 1; i * i <= area; ++i) {

if (area % i == 0)

width = i;

}

height = area/width;

vector<int> result;

result.push_back(height);

result.push_back(width);

return result;

}

};

===========================================================
SEE OUTPUT
clang version gs/RELEASE_70 main.cpp saved 2 #include«vector» 3 using namespace std; 4 5vector<int> constructRectangle(int ar

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
02. For a web developer, it is very important to know how to design a web page's size. So, given ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please cross check your answer for better rating. thanks! 2. (10 points) A manufacturer wishes to...

    please cross check your answer for better rating. thanks! 2. (10 points) A manufacturer wishes to design an open box (no top) from a rectangular piece of cardboard having area 200 cm². This box with no top is to be constructed by removing squares of side length 2cm from each corner and folding up the remaining flaps. 2 = 1 1 = 2 W W (a) (5 points) If the rectangle has length L and width W, find a function...

  • Task: Tasks to complete: ------------------------------------------------------------------------------------------------------------------------------------------ given code: --------------------...

    Task: Tasks to complete: ------------------------------------------------------------------------------------------------------------------------------------------ given code: ------------------------------------------------------------------------------------------------------------------------------------------ main.cpp #include #include "rectangleType.h" using namespace std; // part e int main() { rectangleType rectangle1(10, 5); rectangleType rectangle2(8, 7); rectangleType rectangle3; rectangleType rectangle4; cout << "rectangle1: " << rectangle1 << endl; cout << "rectangle2: " << rectangle2 << endl; rectangle3 = rectangle1 + rectangle2;    cout << "rectangle3: " << rectangle3 << endl; rectangle4 = rectangle1 * rectangle2;    cout << "rectangle4: " << rectangle4 << endl; if (rectangle1 > rectangle2) cout << "Area...

  • Design an original, professional web site following the specifications listed below. This web sit...

    Design an original, professional web site following the specifications listed below. This web site will be for a business you plan to set up for yourself or for someone else. The following is a detailed list of the requirements for your web site. READ them carefully. Instructions - Web Site Requirements for the web site: General: You will thoroughly test all your pages in more than one browser. All links MUST work. All graphics must show on the page. All...

  • Maybe it’s easier to imagine the tank on its side so that the depth gauge is...

    Maybe it’s easier to imagine the tank on its side so that the depth gauge is inserted horizontally if you do this you must express the equation as a function of y and integrate that function. Please use the ellipse formula, and compute the volume of liquid by trapezoidal integral and function you altered for the ellipse formula. MUST contain following function: Void trapezoidal_integral (double depth, int n, double width, double height, double length, double *integral_result) Sample output: Enter the...

  • Please pay special attention to the question asked. Code written must work when replacing it for...

    Please pay special attention to the question asked. Code written must work when replacing it for "//write your code here" in the image below. Must be in C++ I only need the code to replace "//write your code here" with. You don't need to resend the given code. The given code in text format for your convenience: #include <iostream> #include <iomanip> using namespace std; //rectangle class class Rectangle { public: double areaOfRectangle(double l, double w) { if (l > 0...

  • Programming: Java: Fixing errors in code help: The errors are in square.java and rectangle.java and they...

    Programming: Java: Fixing errors in code help: The errors are in square.java and rectangle.java and they both say: constructor Shape in class Shape cannot be applied to given types; required: no arguments found: String reason: actual and formal argument lists differ in length The directions say: The files Shape.java and TestArea.java have been finished already, YOU DONT ADD ANYTHING TO THESE TWO. According to the requirement, you need to modify in Square.java and Rectangle.java, respectively a. Implementing constructor with no...

  • 3.2 Simple Bandpass Filter Design The L-point averaging filter is a lowpass filter. Its passband width...

    3.2 Simple Bandpass Filter Design The L-point averaging filter is a lowpass filter. Its passband width is controlled by L, being inversely proportional to L. In fact, you can use the GUI altidemo to view the frequency response for different averagers and measure the passband widths. It is also possible to create a filter whose passband is centered around some frequency other than zero. One simple way to do this is to define the impulse response of an L-point FIR...

  • Please answer question 7.11 that is modified from the book, thank you! uent welr IS located...

    Please answer question 7.11 that is modified from the book, thank you! uent welr IS located on Lle periphery of each tank. Calculate the surface overflow rate, etention time, and weir loading rates. If one tank is taken out of detention time? Is the design adequate for the average flow with the three tanks in service? m3/d. The engineer wishes to use rectangular clarifiers for primary 18 Fundamentals of wastewater treatment and engineering treatment. Design the rectangular tanks for a...

  • Please help me to write a program in C++ with comments and to keep it simple...

    Please help me to write a program in C++ with comments and to keep it simple as possible. Thank you! Here is my program I have done before and that need to be change: #include <iostream> #include <iomanip> using namespace std; // function prototype – returning one value double cylvol(double, double); // Note: two data types inside brackets double surfarea(double, double); // Note: two data types inside brackets int main() { double r, l, V, S; cout << setprecision(2) <<...

  • Please help with my car traffic simulator! Code that I already have below, I do not know how to...

    Please help with my car traffic simulator! Code that I already have below, I do not know how to start it off! public class IntersectionSimulation { private final static int EAST_WEST_GREEN_TIME = 30 ; private final static int[] NORTH_SOUTH_GREEN_TIMES = { 20, 24, 30, 42 } ; private final static int[] CAR_INTERSECTION_RATES = { 3, 5, 10 } ; private final static int[] CAR_QUEUEING_RATES = { 5, 10, 30 } ; private final static int[] EXPERIMENT_DURATIONS = { 3*60, 5*60,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT