How to think like a Computer Scientist: 课后习题第七章 11-13

来源:互联网 发布:朝鲜高仿人民币 淘宝 编辑:程序博客网 时间:2024/05/03 10:56

#-------------------------------------------------------------------------------# Name:        module1# Purpose:## Author:      penglaixy## Created:     27/07/2013# Copyright:   (c) penglaixy 2013# Licence:     <your licence>#-------------------------------------------------------------------------------import sysimport turtleimport timedef adjust_window(t):        t.penup()        t.right(90)        t.forward(100)        t.left(90)        t.pendown()def test(did_pass):    '''    print the result of a test    '''    linenum = sys._getframe(1).f_lineno    if did_pass:        msg = 'Test at line {0} ok'.format(linenum)    else:        msg = 'Test at line {0} failed'.format(linenum)    print msgdef draw_shape(angle_list):    tess = turtle.Turtle()    wn = turtle.Screen()    adjust_window(tess)    wn.bgcolor('lightgreen')    tess.color('navy blue')    tess.pensize(10)    for (angle, step) in angle_list:        tess.left(angle)        tess.forward(step)    time.sleep(8)    wn.bye()def draw_drunk_priate():    angle_list = [(160, 200),(-43, 100), (270, 80), (-43, 120)]    draw_shape(angle_list)def draw_house():    angle_list = [(90,150),(30,150),(120,150),(120,150),(225,216),(225,150),(225,216),(225,150)]    draw_shape(angle_list)def test_suite():    '''    Run the suite of tests for code in this module    '''    draw_drunk_priate()    #draw_house()def main():    test_suite()if __name__ == '__main__':    main()

下面这段话是从维基百科中搜索到的:
http://en.wikipedia.org/wiki/Eulian_path
In graph theory, an Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge exactly once. Similarly, an Eulerian circuit or Eulerian cycleis an Eulerian trail which starts and ends on the same vertex. 
Euler proved that a necessary condition for the existence of Eulerian circuits is that all vertices in the graph have an even degree,(每个顶点都有偶数个角度) and stated without proof that connected graphs with all vertices of even degree have an Eulerian circuit. 
The term Eulerian graph has two common meanings in graph theory. One meaning is a graph with an Eulerian circuit, and the other is a graph with every vertex of even degree. These definitions coincide for connected graphs.
For the existence of Eulerian trails it is necessary that no more than two vertices have an odd degree(有奇数个角度的顶点个数不大于两个); this means the K?nigsberg graph is not Eulerian. If there are no vertices of odd degree, all Eulerian trails are circuits. If there are exactly two vertices of odd degree(我们画的房子的最底下的两个顶点的角度个数都是3,说的就是这种情况), all Eulerian trails start at one of them and end at the other. A graph that has an Eulerian trail but not an Eulerian circuit is called semi-Eulerian.


第13题,除了第三个第四个图形不能画,其他的都可以,我没有试过,只是根据角度判断的,有兴趣的自己试着画吧

原创粉丝点击