Skip to content

Instantly share code, notes, and snippets.

@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;
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
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)
@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
@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:2655592
Created May 10, 2012 20:13
Ornstein-Unlenbeck in Maple
restart;
with(Statistics):
STDNORM:=proc( ) local ij,U1,U2,S,B,X1;global i,X2;
if type(i,boolean)then
if (i) then
i:=not(i);X2;
else
for ij from 1 to infinity do
U1:=evalf(2.0*rand()/10^12)-1.0;
U2:=evalf(2.0*rand()/10^12)-1.0;
test
@mac-r
mac-r / sorted_array.rb
Created August 14, 2012 21:59
Binary Heaps in the Context of Prioritization #1
def sorted_array_shifter(length, n)
random_array = (1..length).to_a.inject(Array.new) do |arr, el|
el = rand(1..el); arr << el;
end
array = random_array.sort {|x,y| y<=>x }
n.times do
array.shift
end
end
@mac-r
mac-r / binary_heap.rb
Created August 14, 2012 22:01
Binary Heaps in the Context of Prioritization #2
def heap_extractor(length, n)
random_array = (1..length).to_a.inject(Array.new) {|arr, el| el = rand(1..el); arr << el;}
array = HeapModule.build_max_heap(random_array)
n.times do
HeapModule.extract_maximum(array)
end
end