Skip to content

Instantly share code, notes, and snippets.

@mac-r
mac-r / gist:1876658
Created February 21, 2012 13:48
Binary search problem with intervals
# basic sample
sample_array = Array.new
i, t = 0, 0
# puts "what is the size of array?"
limit = 50 #gets.chomp.to_i
#puts "what is the maximum size of identical numbers set?"
max_rand = 15 #gets.chomp.to_i
#puts "what do you want to find X, [L..R]? Input x l r!!!"
#xlr = gets.split().map(&:to_i)
l,r = 0, 50 #xlr[0],xlr[1],xlr[2]
@mac-r
mac-r / gist:1863707
Created February 19, 2012 13:01
Email task 19 February
range_inp = gets.split().map(&:to_i)
x = gets.chomp.to_i
l = range_inp[0]
r = range_inp[1]
m = (r - l)*0.5+l
(x <= midpoint)? (range = (l..m)):(range = (m..r))
enum = 0
range.to_a.each do |y|
if y == x
enum = enum + 1
a, b = Array.new, Array.new
total = 0
gets.to_i.times do
a << gets.to_i
end
gets.to_i.times do
b << gets.to_i
end
b.each do |date|
a.include?(date)? (total = total + 1):(total)
a = Array.new
b = Array.new
gets.chomp.to_i.times do
a << gets.chomp.to_i
end
a.sort!{|x,y| x <=> y}
while gets != "###" do
gets.chomp.to_i.times do
b << a[gets.chomp.to_i-1]
end
i = gets.chomp.to_i
input = gets.split().map(&:to_i).sort
sum = 0
positive = 0
input.each do |inp|
m = 0
while(m/inp.to_f <= 0.5 && positive/i.to_f <= 0.5) do
m = m + 1
end
positive = positive + 1
@mac-r
mac-r / Timus
Created February 12, 2012 23:42
My unsolved problem at Timus, 1025
#include<stdio.h>
int main() {
int i = 0,m = 0, left;
double minx[left], ppl[left], res;
double d1 = 5, d2 = 10;
scanf("%d",&left);
for(i=0;i<left;i++){
scanf("%lf",&ppl[i]);
minx[i] = 0;