A - Obesity 解説 by en_translator
If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
Original proposer: vwxyz
\(H[\mathrm{cm}]\) can be converted to meters by \(\frac{H}{100}[\mathrm{m}]\). According to the definition in the problem statement,
\(\mathrm{BMI}[\mathrm{kg}/\mathrm{m}^2]=\frac{10^4 \times W}{H^2}[\mathrm{kg}/\mathrm{m}^2]\).
It suffices to determine if this is greater than or equal to \(25\).
This inequality is equivalent to:
\(10^4 \times W \geq 25 \times H^2\)
\(400 \times W \geq H^2\).
It suffices to implement this.
Supplement
This topic may be rather advanced for a Problem A, but using decimal types to compare \(\frac{10^4 \times W}{H^2} \geq 25\) is error-prone.
In case of this problem, the constraints guarantee that \(H\) and \(W\) is not very large, and \(25.0\) can be precisely represented with a floating-point type, so comparing \(\frac{10^4 \times W}{H^2}\) and \(25\) is highly likely to get AC, but it is safer to turn it into an integer comparison.
The test cases include one for which comparing \(\frac{W}{(\frac{H}{100})^2}\) and \(25\) will be judged WA (Wrong Answer).
Sample code in C++:
#include <bits/stdc++.h>
using namespace std;
int main(){
int H,W;
cin>>H>>W;
string ans;
if(400*W>=H*H){
ans="Yes";
}
else{
ans="No";
}
cout<<ans<<"\n";
}
Sample code in Python:
H,W=map(int,input().split())
if 400*W>=H*H:
ans="Yes"
else:
ans="No"
print(ans)
投稿日時:
最終更新: