কনসেপ্ট
খরচের রেঞ্জ (lowCost থেকে upCost) এবং পরিমাণের রেঞ্জ (lowQuant থেকে upQuant) দেওয়া আছে। ratio r = cost/quantity পাওয়া যায় কিনা যাচাই করুন যেখানে lowCost ≤ cost ≤ upCost এবং lowQuant ≤ quantity ≤ upQuant।
ইনপুট ১
lowCost=2, upCost=10, lowQuant=3, upQuant=9, r=3
আউটপুট ১
Yes
quantity=3 হলে cost=9 যা রেঞ্জের ভিতরে।
ইনপুট ২
lowCost=15, upCost=31, lowQuant=6, upQuant=13, r=8
আউটপুট ২
No
quantity=6 হলে cost=48 যা ১৫-৩১ রেঞ্জের বাইরে।
পদ্ধতি
cost = quantity × r। lowQuant থেকে upQuant পর্যন্ত লুপ চালিয়ে cost = i*r গণনা করুন। যদি কোনো cost lowCost এবং upCost-এর মধ্যে পড়ে তবে "Yes", নয় তবে "No"।
উদাহরণ (C++ কোড)
// C++ প্রোগ্রাম: অনুপাত r পাওয়া যায় কিনা
#include <bits/stdc++.h>
using namespace std;
bool isRatioPossible1(int lowCost1, int upCost1, int lowQuant1, int upQuant1, int r1) {
for (int i = lowQuant1; i <= upQuant1; i++) {
int ans1 = i * r1;
if (lowCost1 <= ans1 && ans1 <= upCost1) return true;
}
return false;
}
int main() {
int lowCost1=2, upCost1=10, lowQuant1=3, upQuant1=9, r1=3;
if (isRatioPossible1(lowCost1,upCost1,lowQuant1,upQuant1,r1)) cout << "Yes";
else cout << "No";
return 0;
}
আউটপুট
Yes