HackerEarth - Golden rectangles Solution
1 min read

HackerEarth - Golden rectangles Solution

HackerEarth - Golden rectangles Solution

You have N rectangles. A rectangle is golden if the ratio of its sides is in between [1.6,1.7], both inclusive. Your task is to find the number of golden rectangles.

Input format

  • First line: Integer N denoting the number of rectangles
  • Each of the N following lines: Two integers W, H denoting the width and height of a rectangle

Output format

  • Print the answer in a single line.

Constraints

1≤N≤105

1≤W, H≤109

SAMPLE INPUT

5
10 1
165 100
180 100
170 100
160 100

SAMPLE OUTPUT

3

Explanation

There are three golden rectangles: (165, 100), (170, 100), (160, 100).

Solution in Python

n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
print(sum(1 for i in a if max(i)/min(i)>=1.6 and max(i)/min(i)<=1.7))

Additional Info,

We use max(i)/min(i) so that always the long the longer side gets divided by the smaller side. That is, either (100,120) or (120,100) our division will be 120/100.

Enjoying these posts? Subscribe for more


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.

×