Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active March 13, 2016 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/ad65e9ffd1ae28648399 to your computer and use it in GitHub Desktop.
Save whatalnk/ad65e9ffd1ae28648399 to your computer and use it in GitHub Desktop.
AtCoder #ABC 034
x, y = gets.chomp.split(" ").map(&:to_i)
if x < y then
puts "Better"
else
puts "Worse"
end
n = gets.chomp.to_i
if n.even? then
puts n - 1
else
puts n + 1
end
w, h = gets.chomp.split.map(&:to_i)
w-=1
h-=1
MOD = 1_000_000_007
def fact(n)
ans = 1
2.upto(n).each do |i|
ans *= i
ans = ans % MOD
end
return ans
end
def calc(a, b, p)
if b == 0 then
return 1
elsif b.even? then
d = calc(a, b/2, p)
return (d * d) % p
else
return (a * calc(a, b - 1, p)) % p
end
end
def comb(n, k)
mul = fact(n+k)
div = (fact(n) * fact(k)) % MOD
inverse = calc(div, MOD - 2, MOD)
return (mul * inverse) % MOD
end
puts comb(w, h)
n, k = gets.chomp.split(" ").map(&:to_i)
a = []
n.times do
w, p = gets.chomp.split(" ").map(&:to_f)
solt = w * p
a << [w, p, solt]
end
a = a.sort_by{|x| -x[1]}
amax = a.shift
pmax = 0
pi = 0
w = 0
solt = 0
(k-1).times do
(n-1).times do |i|
tmp = (amax[2] + a[i][2]) / (amax[0] + a[i][0])
if tmp > pmax then
pmax = tmp
w = amax[0] + a[i][0]
solt = amax[2] + a[i][2]
pi = i
end
end
a.delete_at(pi)
i = (0...a.size).bsearch{|x| a[x][1] < pmax}
a.insert(i, [w, pmax, solt])
amax = a.shift
n -= 1
pmax = 0
end
puts amax[1]
n, k = gets.chomp.split.map(&:to_i)
a = []
n.times do
w, p = gets.chomp.split(" ").map(&:to_f)
a << [w, p]
end
class Hello
def initialize(n, k, a)
@n = n
@k = k
@a = a
@lower = 0.0
@upper = 100.0
end
attr_accessor :lower
def check(mid)
ans = 0
solt = []
@n.times do |i|
solt << @a[i][0] * (@a[i][1] - mid)
end
solt.sort!
solt.pop(@k).each do |i|
ans += i
end
if (ans >= 0) then
return true
else
return false
end
end
def calc()
mid = (@lower + @upper) / 2
if self.check(mid) then
@lower = mid
else
@upper = mid
end
end
end
x = Hello.new(n, k, a)
100.times do
x.calc()
end
puts x.lower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment