Problem:


Koch Curve

Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.

The Koch curve is well known as a kind of fractals.

You can draw a Koch curve in the following algorithm:

Divide a given segment (p1, p2) into three equal segments.

Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.

Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).

You should start (0, 0), (100, 0) as the first segment.

Input

An integer n is given.

Output

Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.

Constraints

 0 ≤ n ≤ 6

Sample Input 1

1

Sample Output 1

0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000

Sample Input 2

2

Sample Output 2

0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000

Notes



Sample input:
1


Sample output:
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000

Submission status: Wrong Answer

Solution code:
def recKF(p1,p2,n):
    if n != 0:
        a = 1/2
        b = 3**(1/2)/2
        s = Point( p1.x + (p2.x-p1.x)/3, p1.y + (p2.y-p1.y)/3 )
        t = Point( p1.x + (p2.x-p1.x)*2/3, p1.y + (p2.y-p1.y)*2/3 )
        v = Point( t.x-s.x, t.y-s.y )
        rot_v = Point( v.x*a - v.y*b, b*v.x + a*v.y )
        u = Point( rot_v.x + s.x, rot_v.y + s.y)
        recKF(p1,s,n-1)
        print(s.x,s.y)
        recKF(s,u,n-1)
        print(u.x,u.y)
        recKF(u,t,n-1)
        print(t.x,t.y)
        recKF(t,p2,n-1)
        
from collections import namedtuple
Point = namedtuple("Point", ["x","y"])
p1 = Point(0,0)
p2 = Point(100,0)
n = int(input())
print(p1.x,p1.y)
recKF(p1,p2,2)
print(p2.x,p2.y)

Submission status: Wrong Answer

Solution code:
def koch_curve(n, x1, y1, x2, y2):
    if n == 0:
        return [(x1, y1), (x2, y2)]
    s_x = (2 * x1 + x2) / 3
    s_y = (2 * y1 + y2) / 3
    t_x = (x1 + 2 * x2) / 3
    t_y = (y1 + 2 * y2) / 3
    # 回転行列を用いて
    u_x = (t_x - s_x) * .5 - (t_y - s_y) * (3 ** .5 / 2) + s_x
    u_y = (t_x - s_x) * (3 ** .5 / 2) + (t_y - s_y) * .5  + s_y
    ret = koch_curve(n - 1, x1, y1, s_x, s_y) + \
        koch_curve(n - 1, s_x, s_y, u_x, u_y) + \
        koch_curve(n - 1, u_x, u_y, t_x, t_y) + \
        koch_curve(n - 1, t_x, t_y, x2, y2)
    return ret
for x, y in koch_curve(int(input()), 0, 0, 100, 0):
    print('{:.4f} {:.4f}'.format(x, y))

Submission status: Wrong Answer

Solution code:
def koch_curve(n, x1, y1, x2, y2):
    if n == 0:
        return [(x1, y1), (x2, y2)]
    s_x = (2 * x1 + x2) / 3
    s_y = (2 * y1 + y2) / 3
    t_x = (x1 + 2 * x2) / 3
    t_y = (y1 + 2 * y2) / 3
    # 回転行列を用いて
    u_x = (t_x - s_x) * .5 - (t_y - s_y) * (3 ** .5 / 2) + s_x
    u_y = (t_x - s_x) * (3 ** .5 / 2) + (t_y - s_y) * .5  + s_y
    ret = koch_curve(n - 1, x1, y1, s_x, s_y) + \
        koch_curve(n - 1, s_x, s_y, u_x, u_y) + \
        koch_curve(n - 1, u_x, u_y, t_x, t_y) + \
        koch_curve(n - 1, t_x, t_y, x2, y2)
    return ret
for x, y in koch_curve(int(input()), 0, 0, 100, 0):
    print('{:.5f} {:.5f}'.format(x, y))

Submission status: Wrong Answer

Solution code:
import math
class Point:
	def __init__(self,x,y):
		self.x=x
		self.y=y
	def __str__(self):
		return str(self.x)+' '+str(self.y)
	
def koch(n,a,b):
	if n==0: return
	s=Point(0,0)
	t=Point(0,0)
	u=Point(0,0)
	th=math.pi*60/180
	s.x=(2*a.x+1*b.x)/3
	s.y=(2*a.y+1*b.y)/3
	t.x=(1*a.x+2*b.x)/3
	t.y=(1*a.y+2*b.y)/3
	u.x=(t.x-s.x)*math.cos(th)-(t.y-s.y)*math.sin(th)+s.x
	u.y=(t.x-s.x)*math.sin(th)-(t.y-s.y)*math.cos(th)+s.y
	
	koch(n-1,a,s)
	print(s)
	koch(n-1,s,u)
	print(u)
	koch(n-1,u,t)
	print(t)
	koch(n-1,t,b)

n=int(input())
a=Point(0,0)
b=Point(100,0)
print(a)
koch(n,a,b)
print(b)

Submission status: Wrong Answer

Solution code:
import math

def koch(d, p1, p2):
    if d == 0:
        return

    s_x = (2 * p1[0] + 1 * p2[0])/3
    s_y = (2 * p1[1] + 1 * p2[1])/3
    s = [s_x, s_y]
    t_x = (1 * p1[0] + 2 * p2[0])/3
    t_y = (1 * p1[1] + 2 * p2[1])/3
    t = [t_x, t_y]
    rotated = 60
    u_x = (t_x - s_x) * math.cos(rotated) - (t_y - s_y) * math.sin(rotated) + s_x
    u_y = (t_x - s_x) * math.sin(rotated) + (t_y - s_y) * math.cos(rotated) + s_y
    u = [u_x, u_y]

    koch(d-1, p1, s)
    print(s)
    koch(d-1, s, u)
    print(u)
    koch(d-1, u, t)
    print(t)
    koch(d-1, t, p2)
    

def main():
    n = int(input())
    p1 = [0.00000000,0.00000000]
    p2 = [100.00000000,0.00000000]
    koch(n, p1, p2)

if __name__=='main':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

"""
コッホ曲線
参考：https://www.mynote-jp.com/entry/2016/04/30/201249
　　　https://atarimae.biz/archives/23930
・回転行列を使うと、向きの変わった座標が出せる。
・そのために行列の計算方法も確認。
　→m行n列成分は、「左の行列のm行目」と「右の行列のn列目」の内積
"""

from math import sin, cos, radians

N = int(input())

def dfs(p1x, p1y, p2x, p2y, depth):
    if depth == N:
        return
    sx = p1x + (p2x-p1x)/3
    tx = p1x + (p2x-p1x)/3*2
    sy = p1y + (p2y-p1y)/3
    ty = p1y + (p2y-p1y)/3*2
    # s,tを基準の位置として左回りに60度回転させる
    ux = sx + (tx-sx) * cos(radians(60)) - (ty-sy) * sin(radians(60))
    uy = sy + (tx-sx) * sin(radians(60)) + (ty-sy) * cos(radians(60))
    # 再帰が終了した場所から出力していけば、線分上の各頂点の順番になる
    dfs(p1x, p1y, sx, sy, depth+1)
    print(sx, sy)
    dfs(sx, sy, ux, uy, depth+1)
    print(ux, uy)
    dfs(ux, uy, tx, ty, depth+1)
    print(tx, ty) 
    dfs(tx, ty, p2x, p2y, depth+1)

print(0, 0)
dfs(0, 0, 100, 0, 0)
print(0, 100)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

class point:
    x = 0
    y = 0

def kock(p1, p2):
    global n
    s = point()
    t = point()
    u = point()
    if n == 0:
        return
    s.x = (2*p1.x+p2.x)/3
    s.y = (2*p1.y+p2.y)/3
    t.x = (p1.x+2*p2.x)/3
    t.y = (p1.y+2*p2.y)/3
    u.x = (t.x-s.x)*math.cos(math.radians(60))-(t.y-s.y)*math.sin(math.radians(60))+s.x
    u.y = (t.x-s.x)*math.sin(math.radians(60))+(t.y-s.y)*math.cos(math.radians(60))+s.y
    n -= 1
    kock(p1, s)
    print(s.x, s.y)
    kock(s, u)
    print(u.x, u.y)
    kock(u, t)
    print(t.x, t.y)
    kock(t, p2)


a = point()
b = point()
b.x = 100
print(a.x, a.y)
kock(a, b)
print(b.x, b.y)

Submission status: Wrong Answer

Solution code:
from math import sqrt
n = int(input())
p1 = complex(0, 0)
p2 = complex(100, 0)
phi = complex(1/2, 3**(1/2)/2)

def makeCurve(p1, p2, cnt):
    if cnt >= n:
        return
    s = p1 + (p2-p1)/3
    t = p1 + (p2-p1)*2/3
    u = (t-s)*phi+s
    
    
    makeCurve(p1, s, cnt + 1)
    print(s.real, s.imag)
    makeCurve(s, u, cnt + 1)
    print(u.real, u.imag)
    makeCurve(u, t, cnt + 1)
    print(t.real, u.imag)
    makeCurve(t, p2, cnt + 1)

print(p1.real, p1.imag)
makeCurve(p1, p2, 0)
print(p2.real, p2.imag)

Submission status: Wrong Answer

Solution code:
import math
import collections

N = int(input())
Point = collections.namedtuple('Point', ['x', 'y'])


def koch(d, p1, p2):
    if d == 0:
        return
    th = math.pi * 60 / 180
    s = Point(x=(2 * p1.x + p2.x) / 3, y=(2 * p1.y + p2.y) / 3)
    t = Point(x=(p1.x + 2 * p2.x) / 3, y=(p1.y + 2 * p2.y) / 3)
    u = Point(x=(t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x,
              y=(t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) - s.y)
    koch(d - 1, p1, s)
    print(s.x, s.y)
    koch(d - 1, s, u)
    print(u.x, u.y)
    koch(d - 1, u, t)
    print(t.x, t.y)
    koch(d - 1, t, p2)


p1 = Point(x=0, y=0)
p2 = Point(x=100, y=0)
print(p1.x, p1.y)
koch(N, p1, p2)
print(p2.x, p2.y)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = [(0, 0)]
def rec(i, lx, ly, rx, ry):
    if i == N:
        return ans
    else:
        x1 = (2 * lx + rx) / 3
        y1 = (2 * ly + ry) / 3
        x3 = (2 * rx + lx) / 3
        y3 = (2 * ry + ly) / 3
        x2 = (lx + rx) / 2
        y2 = (x3 - x1) * math.sin(2*math.pi/3) \
             + (y3 - y1) * math.cos(2*math.pi/3) + y1
        

        rec(i+1, lx, ly, x1, y1)
        ans.append((x1, y1))

        rec(i+1, x1, y1, x2, y2)
        ans.append((x2, y2))

        rec(i+1, x2, y2, x3, y3)
        ans.append((x3, y3))

        rec(i+1, x3, y3, rx, ry)

        return ans
        

answer = rec(0, 0, 0, 100, 0)
answer.append((100, 0))
for pair in answer:
    print(*pair)

Submission status: Wrong Answer

Solution code:
import math
sin60 = math.sin(60*math.pi/180)
def koch(n,p1,p2):
    if n==0:
        return
    s = [(2*p1[0]+1*p2[0])/3., (2*p1[1]+1*p2[1])]
    t = [(1*p1[0]+2*p2[0])/3., (1*p1[1]+2*p2[1])]
    u = [(t[0]-s[0])*0.5 - (t[1]-s[1])*sin60+ s[0],
        (t[0]-s[0])*sin60 + (t[1]-s[1])*0.5 + s[1]]
    koch(n-1,p1,s)
    print s[0],s[1]
    koch(n-1,s,u)
    print u[0],u[1]
    koch(n-1,u,t)
    print t[0],t[1]
    koch(n-1,t,p2)
       
n = int(raw_input())
p1 = (0,0)
p2 = (100,0)
print p1[0],p1[1]
koch(n,p1,p2)
print p2[0],p1[1]

Submission status: Wrong Answer

Solution code:
import math


def koch(n, p1, p2):
    if n == 0:
        return
    s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1] / 3)]
    t = [(p1[0] + 2 * p2[0] / 3), (p1[1] + 2 * p2[1] / 3)]
    u = [(t[0] - s[0]) * math.cos(math.radians(60))
         - (t[1] - s[1]) * math.sin(math.radians(60)) + s[0],
         (t[0] - s[0]) * math.sin(math.radians(60))
         + (t[1] - s[1]) * math.cos(math.radians(60)) + s[1]]

    koch(n - 1, p1, s)
    print(s[0], s[1])
    koch(n - 1, s, u)
    print(u[0], u[1])
    koch(n - 1, u, t)
    print(t[0], t[1])
    koch(n - 1, t, p2)

n = int(input())
p1 = (0, 0)
p2 = (100, 0)
print(p1[0], p1[1])
koch(n, p1, p2)
print(p2[0], p1[1])

Submission status: Wrong Answer

Solution code:
import math


def koch(n, p1, p2):
    if n == 0:
        return
    s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1] / 3)]
    t = [(p1[0] + 2 * p2[0] / 3), (p1[1] + 2 * p2[1] / 3)]
    u = [(t[0] - s[0]) * math.cos(math.radians(60))
         - (t[1] - s[1]) * math.sin(math.radians(60)) + s[0],
         (t[0] - s[0]) * math.sin(math.radians(60))
         + (t[1] - s[1]) * math.cos(math.radians(60)) + s[1]]

    koch(n - 1, p1, s)
    print(s[0], s[1])
    koch(n - 1, s, u)
    print(u[0], u[1])
    koch(n - 1, u, t)
    print(t[0], t[1])
    koch(n - 1, t, p2)

n = int(input())
p1 = (0, 0)
p2 = (100, 0)
print(p1[0], p1[1])
koch(n, p1, p2)
print(p2[0], p2[1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


SIN60 = 0.86602540378
COS60 = 0.5


class KochCurve(object):

    def __init__(self, n, p1=(0.0, 0.0), p2=(100.0, 0.0)):
        self.depth = n
        self.p1_init = p1
        self.p2_init = p2
        self.points = [p1]

    def koch(self, n=None, p1=None, p2=None):
        if n is None:
            n = self.depth
        if p1 is None:
            p1 = self.p1_init
        if p2 is None:
            p2 = self.p2_init
        if n != 0:
            s = ((2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3)
            t = ((p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3)
            ux = (t[0] - s[0]) * COS60 - (t[1] - s[1]) * SIN60 + s[0]
            uy = (t[0] - s[0]) * SIN60 - (t[1] - s[1]) * COS60 + s[1]
            u = (ux, uy)
            self.koch(n - 1, p1, s)
            self.points.append(s)
            self.koch(n - 1, s, u)
            self.points.append(u)
            self.koch(n - 1, u, t)
            self.points.append(t)
            self.koch(n - 1, t, p2)

    def draw_koch(self):
        self.koch()
        self.points.append(self.p2_init)


def main():
    k = KochCurve(n=int(input()))
    k.draw_koch()
    for p in k.points:
        print("{x:.8f} {y:.8f}".format(x=p[0], y=p[1]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(raw_input())

th = math.pi * 60.0 / 180.0

def split(x,y):
    s = ((2*x[0]+y[0])/3, (2*x[1]+y[1])/3)
    t = ((x[0]+2*y[0])/3, (x[1]+2*y[1])/3)
    u = ((t[0]-s[0])*math.cos(th) - (t[1]-s[1])*math.sin(th) + s[0], (t[0]-s[0])*math.sin(th) + (t[1]-s[1])*math.cos(th) + s[1])
    return (s,u,t)


s = (0.,0.)
t = (100.,0.)
points = []
points.append(s)
points.append(t)
for i in range(n):
    new_points = []
    j = 0
    while True:
        s,u,t = split(points[j],points[j+1])
        new_points.extend((points[j],s,u,t,points[j+1]))
        j += 1
        if j+1 >= len(points): break
    points = new_points
for p in points:
    print p[0],p[1]

Submission status: Wrong Answer

Solution code:
from math import sqrt

n = int(input())
sin60 = sqrt(3) / 2
cos60 = 1 / 2


def koch(x1, y1, x2, y2, depth):
    global sin60, cos60, n
    dx, dy = x2 - x1, y2 - y1
    dx3, dy3 = dx / 3, dy / 3
    xs, ys = x1 + dx3, y1 + dy3
    xt, yt = x2 - dx3, y2 - dy3
    xu, yu = xs + cos60 * dx3 - sin60 * dy3, ys + sin60 * dx3 + cos60 * dy3
    has_next = depth < n
    if has_next:
        depth += 1
        for xy in koch(x1, y1, xs, ys, depth):
            yield xy
    yield (xs, ys)
    if has_next:
        for xy in koch(xs, ys, xu, yu, depth):
            yield xy
    yield (xu, yu)
    if has_next:
        for xy in koch(xu, yu, xt, yt, depth):
            yield xy
    yield (xt, yt)
    if has_next:
        for xy in koch(xt, yt, x2, y2, depth):
            yield xy


print(0.0, 0.0)
for xy in koch(0.0, 0.0, 100.0, 0.0, 1):
    print(*xy)
print(100.0, 0.0)

Submission status: Wrong Answer

Solution code:
import math
T = []

class Vect:
    def __init__(self,x,y):
        self.x = x
        self.y = y


def hoge(p,q):
    ax = q.x-p.x
    ay = q.y-p.y
    bx = ax/5 - ay*math.sqrt(3)/2
    by = ax*math.sqrt(3)/2 + ay/2
    nb = Vect(p.x+bx,p.y+by)
    return nb

def koch(p,q,n):
    if n == 0:
        T.append(p)
    else:
        s = Vect(p.x+(q.x-p.x)/3,p.y+(q.y-p.y)/3)
        t = Vect(p.x+2*(q.x-p.x)/3, p.y+2*(q.y-p.y)/3)
        u = hoge(s,t)
        koch(p,s,n-1)
        koch(s,u,n-1)
        koch(u,t,n-1)
        koch(t,q,n-1)
        
n = int(input())

koch(Vect(0,0),Vect(100,0),n)
T.append(Vect(100,0))

for i in T:
    print("%f %f"%(i.x,i.y))

Submission status: Wrong Answer

Solution code:
import math
T = []

class Vect:
    def __init__(self,x,y):
        self.x = x
        self.y = y


def hoge(p,q):
    ax = q.x-p.x
    ay = q.y-p.y
    bx = ax/5 - ay*math.sqrt(3)/2
    by = ax*math.sqrt(3)/2 + ay/2
    nb = Vect(p.x+bx,p.y+by)
    return nb

def koch(p,q,n):
    if n == 0:
        T.append(p)
    else:
        s = Vect(p.x+(q.x-p.x)/3,p.y+(q.y-p.y)/3)
        t = Vect(p.x+2*(q.x-p.x)/3, p.y+2*(q.y-p.y)/3)
        u = hoge(s,t)
        koch(p,s,n-1)
        koch(s,u,n-1)
        koch(u,t,n-1)
        koch(t,q,n-1)
        
n = int(input())

koch(Vect(0,0),Vect(100,0),n)
T.append(Vect(100,0))

for i in T:
    print("%.8f %.8f"%(i.x,i.y))

Submission status: Wrong Answer

Solution code:
import math
n = int(raw_input())

p1_x = float(0)
p1_y = float(0)
p2_x = float(100)
p2_y = float(0)

def KC(i, n, x1, y1, x2, y2):
	if i < n:
		s_x = (2*x1+x2)/3.0
		s_y = (2*y1+y2)/3.0
		t_x = (x1+2*x2)/3.0
		t_y = (y1+2*y2)/3.0
		u_x = (t_x - s_x)*math.cos(math.pi/3) - (t_y - s_y)*math.sin(math.pi/3) + s_x
		u_y = (t_y - s_y)*math.cos(math.pi/3) + (t_x - s_x)*math.sin(math.pi/3) + s_y
		print s_x, s_y
		print u_x, u_y
		print t_x, t_y
		KC(i+1, n, p1_x, p1_y, s_x, s_y)
		KC(i+1, n, s_x, s_y, u_x, u_y)
		KC(i+1, n, u_x, u_y, t_x, t_y)
		KC(i+1, n, t_x, t_y, p2_x, p2_y)

print p1_x, p1_y
KC(0, n, p1_x, p1_y, p2_x, p2_y)
print p2_x, p2_y

Submission status: Wrong Answer

Solution code:
import math
n = int(raw_input())

p1_x = float(0)
p1_y = float(0)
p2_x = float(100)
p2_y = float(0)

def KC(i, n, x1, y1, x2, y2):
	if i < n:
		s_x = (2*x1+x2)/3.0
		s_y = (2*y1+y2)/3.0
		t_x = (x1+2*x2)/3.0
		t_y = (y1+2*y2)/3.0
		u_x = (t_x - s_x)*math.cos(math.pi/3) - (t_y - s_y)*math.sin(math.pi/3) + s_x
		u_y = (t_y - s_y)*math.cos(math.pi/3) + (t_x - s_x)*math.sin(math.pi/3) + s_y
		KC(i+1, n, p1_x, p1_y, s_x, s_y)
		print s_x, s_y
		KC(i+1, n, s_x, s_y, u_x, u_y)
		print u_x, u_y
		KC(i+1, n, u_x, u_y, t_x, t_y)
		print t_x, t_y
		KC(i+1, n, t_x, t_y, p2_x, p2_y)

print p1_x, p1_y
KC(0, n, p1_x, p1_y, p2_x, p2_y)
print p2_x, p2_y

Submission status: Wrong Answer

Solution code:
import math

class Point:
    def __init__(self, num_x, num_y):
        self.x = num_x
        self.y = num_y

def kock(n, p1, p2):
    if n == 0:
        return

    s = Point(0, 0)
    t = Point(0, 0)
    u = Point(0, 0)

    s.x = (2 * p1.x + p2.x) / 3.0
    s.y = (2 * p1.y + p2.y) / 3.0
    t.x = (p1.x + p2.x * 2) / 3.0
    t.y = (p1.y + p2.y * 2) / 3.0
    u.x = (t.x - s.x) * math.cos(math.pi / 3) - (t.y - s.y) * math.cos(math.pi / 3) + s.x
    u.y = (t.x - s.x) * math.sin(math.pi / 3) - (t.y - s.y) * math.cos(math.pi / 3) + s.y

    kock(n - 1, p1, s)
    print "%.8f %.8f" % (s.x, s.y)
    kock(n - 1, s, u)
    print "%.8f %.8f" % (u.x, u.y)
    kock(n - 1, u, t)
    print "%.8f %.8f" % (t.x, t.y)
    kock(n - 1, t, p2)

n = input()

p1 = Point(0, 0)
p2 = Point(100, 0)

print "%.8f %.8f" % (p1.x, p1.y)
kock(n, p1, p2)
print "%.8f %.8f" % (p2.x, p2.y)

Submission status: Wrong Answer

Solution code:
import math

class Point:
    def __init__(self, num_x, num_y):
        self.x = num_x
        self.y = num_y

def kock(n, p1, p2):
    if n == 0:
        return

    s = Point(0, 0)
    t = Point(0, 0)
    u = Point(0, 0)

    s.x = (2 * p1.x + p2.x) / 3.0
    s.y = (2 * p1.y + p2.y) / 3.0
    t.x = (p1.x + p2.x * 2) / 3.0
    t.y = (p1.y + p2.y * 2) / 3.0
    u.x = (t.x - s.x) * math.cos(math.pi / 3) - (t.y - s.y) * math.sin(math.pi / 3) + s.x
    u.y = (t.x - s.x) * math.sin(math.pi / 3) - (t.y - s.y) * math.cos(math.pi / 3) + s.y

    kock(n - 1, p1, s)
    print "%.8f %.8f" % (s.x, s.y)
    kock(n - 1, s, u)
    print "%.8f %.8f" % (u.x, u.y)
    kock(n - 1, u, t)
    print "%.8f %.8f" % (t.x, t.y)
    kock(n - 1, t, p2)

n = input()

p1 = Point(0, 0)
p2 = Point(100, 0)

print "%.8f %.8f" % (p1.x, p1.y)
kock(n, p1, p2)
print "%.8f %.8f" % (p2.x, p2.y)

Submission status: Wrong Answer

Solution code:
def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return

  th = math.pi*60.0/180.0

  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_x + 1.0*b_x)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_x + 2.0*b_x)/3.0
  u_x = (t_x - s_x)*math.cos(th) + (t_y - s_y)*math.sin(th) + s_x
  u_y = (t_x - s_x)*math.sin(th) + (t_y - s_y)*math.cos(th) + s_y

  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %8.f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %8.f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %8.f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)



import math
n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0

print '%.8f %8.f' % (a_x, a_y)
koch(n, a_x, a_y, b_x, b_y)
print '%.8f %8.f' % (b_x, b_y)

Submission status: Wrong Answer

Solution code:
def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return
 
  th = math.pi*60.0/180.0
 
  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_x + 1.0*b_x)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_x + 2.0*b_x)/3.0
  u_x = (t_x - s_x)*math.cos(th) + (t_y - s_y)*math.sin(th) + s_x
  u_y = (t_x - s_x)*math.sin(th) + (t_y - s_y)*math.cos(th) + s_y
 
  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %8.f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %8.f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %8.f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)
 
 

import math
n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0
 
print '%.8f %8.f' % (a_x, a_y)
koch(n, a_x, a_y, b_x, b_y)
print '%.8f %8.f' % (b_x, b_y)

Submission status: Wrong Answer

Solution code:
def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return
 
  th = math.pi*60.0/180.0
 
  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_x + 1.0*b_x)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_x + 2.0*b_x)/3.0
  u_x = (t_x - s_x)*math.cos(th) + (t_y - s_y)*math.sin(th) + s_x
  u_y = (t_x - s_x)*math.sin(th) + (t_y - s_y)*math.cos(th) + s_y
 
  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %8.f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %8.f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %8.f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)
 
 

import math
n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0
 
print '%.8f %8.f\n' % (a_x, a_y)
koch(n, a_x, a_y, b_x, b_y)
print '%.8f %8.f\n' % (b_x, b_y)

Submission status: Wrong Answer

Solution code:
from math import sin
from math import cos
from math import pi

class point():
   def __init__(self,_x,_y):
       self.x = _x
       self.y = _y

def kock (n, p1, p2):
    if n == 0:
        return
    s = point((2. * p1.x + 1. * p2.x) / 3., (2. * p1.y + 1. *p2.y) / 3.)
    t = point((1. * p1.x + 2. * p2.x) / 3., (1. * p1.y + 2. *p2.y) / 3.)
    u = point((t.x - s.x) * cos(pi / 3.) - (t.y - s.y) * sin(pi / 3.) + s.x, (t.x - s.x) * sin(pi / 3.) - (t.y - s.y) * cos(pi / 3) + s.y)

    kock(n - 1, p1, s)
    print '%s %s' % (str(s.x), str(s.y))
    kock(n - 1, s, u)
    print '%s %s' % (str(u.x), str(u.y))
    kock(n - 1, u, t)
    print '%s %s' % (str(t.x), str(t.y))
    kock(n - 1, t, p2)
    print '%s %s' % (str(p2.x), str(p2.y))

n = input();

p1 = point(0., 0.)
p2 = point(100., 0.)

print '%s %s' % (str(p1.x), str(p1.y))
kock(n, p1, p2)

Submission status: Wrong Answer

Solution code:
from math import sin
from math import cos
from math import pi

class point():
   def __init__(self,_x,_y):
       self.x = _x
       self.y = _y

def kock (n, p1, p2):
    if n == 0:
        return
    s = point((2. * p1.x + 1. * p2.x) / 3., (2. * p1.y + 1. *p2.y) / 3.)
    t = point((1. * p1.x + 2. * p2.x) / 3., (1. * p1.y + 2. *p2.y) / 3.)
    u = point((t.x - s.x) * cos(pi / 3.) - (t.y - s.y) * sin(pi / 3.) + s.x, (t.x - s.x) * sin(pi / 3.) - (t.y - s.y) * cos(pi / 3) + s.y)

    kock(n - 1, p1, s)
    print '%s %s' % (str(s.x), str(s.y))
    kock(n - 1, s, u)
    print '%s %s' % (str(u.x), str(u.y))
    kock(n - 1, u, t)
    print '%s %s' % (str(t.x), str(t.y))
    kock(n - 1, t, p2)
    print '%s %s' % (str(p2.x), str(p2.y))

n = input();

p1 = point(0., 0.)
p2 = point(100., 0.)

print '%s %s' % (str(p1.x), str(p1.y))
if n == 0:
    print '%s %s' % (str(p2.x), str(p2.y))
else:
    kock(n, p1, p2)

Submission status: Wrong Answer

Solution code:
from math import sin
from math import cos
from math import pi

class point():
   def __init__(self,_x,_y):
       self.x = _x
       self.y = _y

def kock (n, p1, p2):
    if n == 0:
        return
    s = point((2. * p1.x + 1. * p2.x) / 3., (2. * p1.y + 1. *p2.y) / 3.)
    t = point((1. * p1.x + 2. * p2.x) / 3., (1. * p1.y + 2. *p2.y) / 3.)
    u = point((t.x - s.x) * cos(pi / 3.) - (t.y - s.y) * sin(pi / 3.) + s.x, (t.x - s.x) * sin(pi / 3.) - (t.y - s.y) * cos(pi / 3) + s.y)

    kock(n - 1, p1, s)
    print '%s %s' % (str(s.x), str(s.y))
    kock(n - 1, s, u)
    print '%s %s' % (str(u.x), str(u.y))
    kock(n - 1, u, t)
    print '%s %s' % (str(t.x), str(t.y))
    kock(n - 1, t, p2)

n = input();

p1 = point(0., 0.)
p2 = point(100., 0.)

print '%s %s' % (str(p1.x), str(p1.y))
kock(n, p1, p2)
print '%s %s' % (str(p2.x), str(p2.y))

Submission status: Wrong Answer

Solution code:
import math
sin60 = math.sin(60*math.pi/180)
def koch(n,p1,p2):
    if n==0:
        return
    s = [(2*p1[0]+1*p2[0])/3, (2*p1[1]+1*p2[1])/3]
    t = [(1*p1[0]+2*p2[0])/3, (1*p1[1]+2*p2[1])/3]
    u = [(t[0]-s[0])*0.5 - (t[1]-s[1])*sin60+ s[0],
        (t[0]-s[0])*sin60 + (t[1]-s[1])*0.5 + s[1]]
    koch(n-1,p1,s)
    print s[0],s[1]
    koch(n-1,s,u)
    print u[0],u[1]
    koch(n-1,u,t)
    print t[0],t[1]
    koch(n-1,t,p2)
        
n = int(raw_input())
p1 = (0,0)
p2 = (100,0)
print p1[0],p1[1]
koch(n,p1,p2)
print p2[0],p1[1]

Submission status: Wrong Answer

Solution code:
import math
n = int(raw_input())
 
p1_x = float(0)
p1_y = float(0)
p2_x = float(100)
p2_y = float(0)
 
def KC(i, n, x1, y1, x2, y2):
    v = [0]*5
    w = [0]*5
    if i < n:
        v[0] = x1
        w[0] = y1
        v[1] = (2*x1+x2)/3.0
        w[1] = (2*y1+y2)/3.0
        v[2] = (x1+2*x2)/3.0
        w[2] = (y1+2*y2)/3.0
        v[3] = (v[2] - v[1])*math.cos(math.pi/3) - (w[2] - w[1])*math.sin(math.pi/3) + v[1]
        w[3] = (w[2] - w[1])*math.cos(math.pi/3) + (v[2] - v[1])*math.sin(math.pi/3) + w[1]
        v[3] = x2
        w[3] = y2
        KC(i+1, n, v[0], w[0], v[1], w[1])
        print v[1], w[1]
        KC(i+1, n, v[1], w[1], v[3], w[3])
        print v[3], w[3]
        KC(i+1, n, v[3], w[3], v[2], w[2])
        print v[2], w[2]
        KC(i+1, n, v[2], w[2], v[4], w[4])
 
print p1_x, p1_y
KC(0, n, p1_x, p1_y, p2_x, p2_y)
print p2_x, p2_y

Submission status: Wrong Answer

Solution code:
import math
n = int(raw_input())
 
p1_x = float(0)
p1_y = float(0)
p2_x = float(100)
p2_y = float(0)
 
def KC(i, n, x1, y1, x2, y2):
    v = [0] * 5
    w = [0] * 5
    if i < n:
        v[0] = x1
        w[0] = y1
        v[1] = (2 * x1 + x2) / 3.0
        w[1] = (2 * y1 + y2) / 3.0
        v[2] = (x1 + 2 * x2) / 3.0
        w[2] = (y1 + 2 * y2) / 3.0
        v[3] = (v[2] - v[1]) * math.cos(math.pi/3) - (w[2] - w[1]) * math.sin(math.pi/3) + v[1]
        w[3] = (w[2] - w[1]) * math.cos(math.pi/3) + (v[2] - v[1]) * math.sin(math.pi/3) + w[1]
        v[4] = x2
        w[4] = y2
        KC(i+1, n, v[0], w[0], v[1], w[1])
        print v[1], w[1]
        KC(i+1, n, v[1], w[1], v[3], w[3])
        print v[3], w[3]
        KC(i+1, n, v[3], w[3], v[2], w[2])
        print v[2], w[2]
        KC(i+1, n, v[2], w[2], v[4], w[4])
 
print p1_x, p1_y
KC(0, n, p1_x, p1_y, p2_x, p2_y)
print p1_x, p1_y

Submission status: Wrong Answer

Solution code:
import math

def kock(n, x1, x2, y1, y2):
    if n == 0:
        return
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy

    kock(n-1, x1, y1, sx, sy)
    print sx, sy
    kock(n-1, sx, sy, ux, uy)
    print ux, uy
    kock(n-1, ux, uy, tx, ty)
    print tx, ty
    kock(n-1, tx, ty, x2, y2)

n = int(raw_input())

angle = math.radians(60*math.pi/180)

p1x =   0.000000000000
p1y =   0.000000000000
p2x = 100.000000000000
p2y =   0.000000000000

print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math

def kock(n, x1, x2, y1, y2):
    if n == 0:
        return
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy

    kock(n-1, x1, y1, sx, sy)
    print sx, sy
    kock(n-1, sx, sy, ux, uy)
    print ux, uy
    kock(n-1, ux, uy, tx, ty)
    print tx, ty
    kock(n-1, tx, ty, x2, y2)

n = int(raw_input())

angle = 60

p1x =   0.000000000000
p1y =   0.000000000000
p2x = 100.000000000000
p2y =   0.000000000000

print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math

def kock(n, x1, x2, y1, y2):
    if n == 0:
        return    
    angle = 60
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy

    kock(n-1, x1, y1, sx, sy)
    print sx, sy
    kock(n-1, sx, sy, ux, uy)
    print ux, uy
    kock(n-1, ux, uy, tx, ty)
    print tx, ty
    kock(n-1, tx, ty, x2, y2)

n = int(raw_input())

p1x =   0.000000000000
p1y =   0.000000000000
p2x = 100.000000000000
p2y =   0.000000000000

print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math

def kock(n, x1, x2, y1, y2):
    if n == 0:
        return
    angle = 60
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy

    kock(n-1, x1, y1, sx, sy)
    print sx, sy
    kock(n-1, sx, sy, ux, uy)
    print ux, uy
    kock(n-1, ux, uy, tx, ty)
    print tx, ty
    kock(n-1, tx, ty, x2, y2)

n = input()

p1x =   0.000000000000
p1y =   0.000000000000
p2x = 100.000000000000
p2y =   0.000000000000

print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math

def kock(n, x1, x2, y1, y2):
    if n == 0:
        return
    angle = math.radians(60)
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy

    kock(n-1, x1, y1, sx, sy)
    print sx, sy
    kock(n-1, sx, sy, ux, uy)
    print ux, uy
    kock(n-1, ux, uy, tx, ty)
    print tx, ty
    kock(n-1, tx, ty, x2, y2)

n = input()

p1x =   0.000000000000
p1y =   0.000000000000
p2x = 100.000000000000
p2y =   0.000000000000

print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math

def kock(n, x1, x2, y1, y2):
    if n == 0:
        return
    angle = math.radians(60)
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy

    kock(n-1, x1, y1, sx, sy)
    print sx, sy
    kock(n-1, sx, sy, ux, uy)
    print ux, uy
    kock(n-1, ux, uy, tx, ty)
    print tx, ty
    kock(n-1, tx, ty, x2, y2)

n = int(raw_input())

p1x = 0.
p1y = 0.
p2x = 100.
p2y = 0.

print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math

def kock(n, x1, x2, y1, y2):
    if n == 0:
        return
    angle = math.radians(60)
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy

    kock(n-1, x1, y1, sx, sy)
    print sx, sy
    kock(n-1, sx, sy, ux, uy)
    print ux, uy
    kock(n-1, ux, uy, tx, ty)
    print tx, ty
    kock(n-1, tx, ty, x2, y2)

n = int(raw_input())

p1x = float(0.)
p1y = float(0.)
p2x = float(100.)
p2y = float(0.)

print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math
n = input()
def koch(n, x, y, x2, y2):
    if n == 0:
        return
 
 
    sx = (2*x+x2)/3
    sy = (2*y+y2)/3
    tx = (2*x2+x)/3
    ty = (2*y2+y)/3
    ux = (tx-sx)*math.cos(math.radians(60)) - (ty-sy)*math.sin(math.radians(60)) +sx
    uy = (tx-sx)*math.sin(math.radians(60)) + (ty-sy)*math.cos(math.radians(60)) + sy
 
    koch( n-1 , x , y , sx , sy )
    print sx , sy
    koch( n-1 , sx , sy , ux , uy )
    print ux , uy
    koch( n-1 , ux , uy , tx , ty )
    print tx , ty
    koch( n-1, tx , ty , x2 , y2 )
 

 
px = 0
py = 0
p_x = 100
p_y = 0
 
print px , py
koch( n , px , py , p_x , p_y )
print p_x , p_y