Code Forces – Round #1 – A – Theater Square

I got The best Submission for this Problem at Code Forces 🙂

Best Submission on Code Forces

The Typical Ruby code for is problem is as following

n,m,a = gets.split
n,m,a = n.to_f, m.to_f, a.to_f
puts (((n/a).ceil)*((m/a).ceil))

which is equivalent to the following code

n,m,a = gets.split
n,m,a = n.to_f, m.to_f, a.to_f
puts (((-n/a).floor)*((-m/a).floor))

but it turn out to be that the ruby interpreter takes the floor of the resulting value. so we only have to make it write it like this.

require 'scanf.rb'
n,m,a = scanf("%d %d %d")
puts ((-n/a)*(-m/a))

this code is my shortest but the require method took lots of space.

require 'scanf.rb'
n,m,a = scanf("%d %d %d")
puts (-n/a)*(-m/a)

and this is the code which I got the best submission for.

m,n,a=gets.split.map(&:to_i)
p -m/a*(-n/a)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: