Created
June 1, 2011 11:20
-
-
Save hauleth/1002134 to your computer and use it in GitHub Desktop.
Rozwiązanie zadań z matury 2011 z informatyki
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
unsigned int sklej(int n) { | |
if(n == 1) | |
return 1; | |
if(n % 2 == 0) | |
return n - 1 + 2*sklej(n/2); | |
return n - 1 + sklej(n/2) + sklej((n+1)/2); | |
} | |
void sklej_fill(unsigned int tab[], size_t size) { | |
size_t i; | |
tab[0] = tab[1] = 1; | |
for(i = 2; i < size; ++i) | |
tab[i] = i - 1 + tab[i/2] + tab[(i+1)/2]; | |
} | |
int main() { | |
int tab[10000], i; | |
sklej_fill(tab, 10000); | |
for(i = 1; i < 10000; ++i) | |
printf("%u\n", tab[i]); | |
return 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Matura { | |
private static int sklej(int i) { | |
if(i < 2) | |
return 1; | |
else | |
return i - 1 + (i % 2 == 1 ? sklej(i/2) + sklej((i+1)/2) : 2*sklej(i/2)); | |
} | |
private static uint[] sklej_gen(uint size) { | |
uint i; | |
uint[] tab = new uint[size]; | |
tab[0] = tab[1] = 1; | |
for(i = 2; i < size; ++i) | |
tab[i] = i - 1 + tab[i/2] + tab[(i+1)/2]; | |
return tab; | |
} | |
public static void Main() { | |
uint[] tab = sklej_gen(10000); | |
for(int i = 0; i < 10000; ++i) | |
System.Console.WriteLine(tab[i]); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
uint sklej(uint n) { | |
if(n == 1) | |
return 1; | |
if(n % 2 == 0) | |
return n - 1 + 2*sklej(n/2); | |
return n - 1 + sklej(n/2) + sklej((n+1)/2); | |
} | |
uint[] sklej_gen(uint size) { | |
uint[] tab; | |
tab.length = size; | |
tab[0] = tab[1] = 1; | |
for(uint i = 2; i < size; ++i) | |
tab[i] = i - 1 + tab[i/2] + tab[(i+1)/2]; | |
return tab; | |
} | |
void main() { | |
uint[] tab = sklej_gen(10000); | |
foreach(n; tab) | |
writefln(n); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Instances | |
sklej :: Integral a => a -> a | |
sklej n | n == 1 = 1 | |
| otherwise = n - 1 + (sklej . floor $ tmp) + (sklej . ceiling $ tmp) | |
where tmp = (/2) $ fromIntegral n | |
sklej_gen :: [Integer] | |
sklej_gen = 1 : (zipWith (+) [1..] (tail >>= zipWith (+) $ replicate 2 =<< sklej_gen)) | |
main :: IO () | |
-- main = putStrLn $ concat $ [ show x ++ "\n" | x <- map sklej [1..10] ] | |
main = putStrLn $ concat [ show x ++ "\n" | x <- take 10000 sklej_gen ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Matura { | |
private static int sklej(int i) { | |
if(i < 2) | |
return 1; | |
else | |
return i - 1 + (i % 2 == 1 ? sklej(i/2) + sklej((i+1)/2) : 2*sklej(i/2)); | |
} | |
private static int[] sklej_gen(int size) { | |
int[] tab = new int[size]; | |
tab[0] = tab[1] = 1; | |
for(int i = 2; i < size; ++i) | |
tab[i] = i - 1 + tab[i/2] + tab[(i+1)/2]; | |
return tab; | |
} | |
public static void main(String[] args) { | |
int[] tab = sklej_gen(10000); | |
for(int i = 0; i < 10000; ++i) | |
System.out.println(tab[i]); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; using Scheme syntax, compiled using GNU Guile | |
(define (sklej n) | |
(if (= n 1) | |
1 | |
(let ((tmp (/ n 2))) | |
(+ (- n 1) (sklej (ceiling tmp)) (sklej (floor tmp)))))) | |
(define (sklej-gen n) | |
(letrec ((loop | |
(lambda (iter ret) | |
(if (= n (length ret)) | |
ret | |
(let* ((tmp (/ iter 2)) | |
(ret (append ret (list (+ (- iter 1) (list-ref ret (ceiling tmp)) (list-ref ret (floor tmp))))))) | |
(loop (+ iter 1) ret)))))) | |
(loop 2 '(1 1)))) | |
;(let loop ((i 1)) | |
; (if (< i 10001) | |
; (begin | |
; (display (sklej i)) | |
; (newline) | |
; (loop (+ i 1))))) | |
(for-each (lambda (a) | |
(begin | |
(display a) | |
(newline))) (sklej-gen 10000)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec sklej = function | |
| 1 -> 1 | |
| n -> if n mod 2 == 0 then | |
n - 1 + 2 * sklej(n/2) | |
else | |
n - 1 + sklej((n+1)/2) + sklej((n-1)/2) | |
;; | |
for i = 1 to 10000 do | |
Printf.printf "%d\n" (sklej i); | |
done;; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program Matura; | |
uses Math; | |
var | |
i : Integer; | |
tab : array[0..10000] of LongInt; | |
function sklej(n : Integer) : Int64; | |
begin | |
if n = 1 then | |
sklej := 1 | |
else if n mod 2 = 0 then | |
sklej := n - 1 + 2 * sklej(n div 2) | |
else | |
sklej := n - 1 + sklej((n-1) div 2) + sklej((n+1) div 2); | |
end; | |
procedure sklej_fill(var tab : array of LongInt); | |
var | |
i : LongInt; | |
begin | |
tab[0] := 1; | |
tab[1] := 1; | |
for i := 2 to high(tab) do | |
begin | |
tab[i] := i - 1 + tab[floor(i/2)] + tab[ceil(i/2)]; | |
end; | |
end; | |
begin | |
//for i := 1 to 10000 do | |
// writeln(sklej(i)); | |
sklej_fill(tab); | |
for i := 1 to 10000 do | |
writeln(tab[i]); | |
end. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
def sklej(n): | |
if n == 1: | |
return 1 | |
elif n % 2 == 0: | |
return n - 1 + 2*sklej(n/2) | |
else: | |
return n - 1 + sklej((n-1)/2) + sklej((n+1)/2) | |
def sklej_gen(n): | |
tab = [1,1] | |
for i in range(2,n): | |
if i % 2 == 0: | |
tab.append(i - 1 + 2*tab[i/2]) | |
else: | |
tab.append(i - 1 + tab[(i+1)/2] + tab[(i-1)/2]) | |
return tab | |
for i in sklej_gen(10000): | |
print i | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
def sklej(n) | |
if n == 1 | |
return 1 | |
elsif n.even? | |
return n - 1 + 2*sklej(n/2) | |
else | |
return n - 1 + sklej((n-1)/2) + sklej((n+1)/2) | |
end | |
end | |
def sklej_gen(size) | |
tab = [1,1] | |
(2..size).each do |i| | |
tab[i] = i - 1 + tab[(i/2.0).floor] + tab[(i/2.0).ceil] | |
end | |
tab | |
end | |
#(1..10000).each {|i| puts sklej(i) } | |
sklej_gen(10000).each {|i| puts i} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment