A - Maxi-Buying Editorial by en_translator
The essential part of this problem is to multiply an integer by \(1.08\) and round it down.
However, computing this process on a decimal type variable is dangerous in competitive programming, as it may cause a precision error.
Instead, for this problem, we consider doing all calculation on an integral type variable.
To come to the point, it is sufficient to multiply \(N\) by \(108\), divide by \(100\), and then round it down.
The operation can be accomplished due to the following property of most programming languages. For example in C++, the operator /
of type int has this property.
When computing the quotient of integral division, the result is its integer part, and the fractional part (the remainder) is rounded down.
With this property, we can implement as follows.
Sample code in Ruby:
input = gets.to_i
input = (input * 108) / 100
if input < 206 then
puts "Yay!\n"
elsif input == 206 then
puts "so-so\n"
else
puts ":(\n"
end
Also, one can perform division on an decimal type (with a care of errors) and perform a virtual rounding-down with a conditional branch. The justification of this solution is after the sample code. Sample code in Visual Basic:
Module ABC206A
Sub Main()
Dim N As Double
N = Console.ReadLine()
N *= 1.08
If N < 206.0 Then
Console.WriteLine("Yay!")
ElseIf 206.0 <= N And N < 207.0
Console.WriteLine("so-so")
Else
Console.WriteLine(":(")
End If
End Sub
End Module
In fact, the following relations hold:
- \(190 \times 1.08= 205.2\)
- \(191 \times 1.08 = 206.28\)
- \(192 \times 1.08 = 207.36\)
These are far enough from the output bound integer. So this time, we can implement with a decimal type with a care of errors. Now, isn’t there an even easier way?
In fact, we can infer from these three equations around the bounds that it is enough to output Yay!
if \(N\le 190\), so-so
if \(N=191\), or :(
if \(N \ge 192\).
The Sample \(3\) was the hint for this solution.
Sample code with Nim:
import strutils
let n = stdin.readLine.parseInt
if n <= 190:
echo "Yay!\n"
elif n == 191:
echo "so-so\n"
else:
echo ":(\n"
posted:
last update: