Skip to content

Instantly share code, notes, and snippets.

View ninoseki's full-sized avatar

Manabu Niseki ninoseki

View GitHub Profile
@ninoseki
ninoseki / 285-div2-a.rb
Created January 14, 2015 22:24
Codeforces#285 Div2-A
def max_score(p, t)
[3 * p / 10, p - (p / 250 * t)].max
end
a, b, c, d = gets.chomp.split.map(&:to_i)
diff = max_score(a, c) - max_score(b, d)
case
when diff > 0
puts 'Misha'
@ninoseki
ninoseki / 285-div2-b.rb
Last active August 29, 2015 14:13
Codeforces#285 Div2-B
# http://codeforces.com/contest/501/problem/B
q = gets.chomp.to_i
queries = []
q.times { queries << gets.chomp.split }
hash = Hash.new { |h, k| h[k] = [] }
queries.each do |old_name, new_name|
root = hash.keys.select { |key| hash[key].last == old_name }.first
if root.nil?
hash[old_name] << new_name
@ninoseki
ninoseki / 290-div2-a.rb
Last active August 29, 2015 14:14
Codeforces#290 Div2-A
# http://codeforces.com/contest/510/problem/A
class Snake
def initialize(n, m)
@n, @m = n, m
end
def draw
rows.each { |row| puts row.join }
end
@ninoseki
ninoseki / 295-div2-a.rb
Last active August 29, 2015 14:16
Codeforces#295 Div2-A
# http://codeforces.com/contest/520/problem/A
class Pangram
def initialize(s)
@chars = s.downcase.chars
end
def is_pangram?
@chars.uniq.length >= ('a'..'z').to_a.length
end
@ninoseki
ninoseki / gist:6161d08436ba1faa12c8
Created March 7, 2015 23:30
Codeforces#294 Div2-A
# http://codeforces.com/contest/519/problem/A
class Board
WEIGHTS = { q: 9, r: 5, b: 3, n: 3, p: 1 }
def initialize(lines)
@pieces = lines.join.chars
end
def which_to_win?
case
@ninoseki
ninoseki / gist:04ee494239d2ec7b1e08
Created March 8, 2015 00:12
Codeforces#294 Div2-B
# http://codeforces.com/contest/519/problem/B
class Errors
def initialize(a, b, c)
@errors = [a, b, c].map(&:sort)
end
def corrected_error(n)
(0..@errors[n - 1].length).each do |idx|
return @errors[n - 1][idx] if @errors[n][idx] != @errors[n - 1][idx]
end
@ninoseki
ninoseki / gist:5b81903b941580200717
Created March 14, 2015 21:08
Codeforces#291 Div2-A
# http://codeforces.com/contest/514/problem/A
digits = gets.chomp.chars.map(&:to_i)
inverted = digits.map.with_index do |n, idx|
case idx
when 0
(9 - n) < n && n != 9 ? 9 - n : n
else
(9 - n) < n ? 9 - n : n
end
@ninoseki
ninoseki / 291-div2-b.rb
Last active August 29, 2015 14:17
Codeforces#291 Div2-B
# http://codeforces.com/contest/514/problem/B
require 'set'
n, x0, y0 = gets.split.map(&:to_f)
set = Set.new
n.to_i.times do
x, y = gets.split.map(&:to_f)
if x == x0
@ninoseki
ninoseki / 297-div2-a.rb
Created March 30, 2015 21:25
Codeforces#297 Div2-A
# http://codeforces.com/contest/525/problem/A
n = gets.to_i
s = gets.chomp.chars
keys = Hash.new(0)
ans = 0
s.each_slice(2) do |key, door|
keys[key] += 1
if keys[door.downcase] >= 1
@ninoseki
ninoseki / 283-div2-a.rb
Created April 27, 2015 22:09
Codeforces#283 Div2-A
# http://codeforces.com/contest/496/problem/A
n = gets.chomp.to_i
numbers = gets.chomp.split.map(&:to_i)
arr = []
first = numbers.first
last = numbers.last
numbers.delete_at 0
numbers.delete_at(numbers.length - 1)