Header Ad

HackerEarth Golden rectangles problem solution

In this HackerEarth Golden rectangles problem 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.


HackerEarth Golden rectangles problem solution


HackerEarth Golden rectangles problem solution.

#include <bits/stdc++.h>
using namespace std;

void solve() {
int n; cin >> n;
int res = 0;
while (n--) {
int w, h; cin >> w >> h;
if (w > h) swap(w, h);
if (16LL * w <= 10LL * h && 10LL * h <= 17LL * w) {
res++;
}
}
cout << res << "\n";
}

int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0), cin.tie(0);
if (argc > 1) {
assert(freopen(argv[1], "r", stdin));
}
if (argc > 2) {
assert(freopen(argv[2], "wb", stdout));
}
solve();
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}

Second solution

#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(a) (lld)((a).size())
#define all(c) (c).begin(),(c).end()
typedef long double ldb;
typedef long long lld;
const lld MOD = 1e9+7;
const lld INF = 1011111111;
const lld LLINF = 1000111000111000111LL;
const ldb EPS = 1e-10;
const ldb PI = 3.14159265358979323;
using namespace std;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
const lld N = 1000005;

int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
lld n,ans = 0,w,h;
cin>>n;
rep(i,1,n+1) {
cin>>w>>h;
if(10*w >= 16*h and 10*w <= 17*h) ans++;
else if(10*h >= 16*w and 10*h <= 17*w) ans++;
else continue;
}
cout<<ans;
return 0;
}


Post a Comment

0 Comments