采用列表和字典存储数据来求解

30个人准备过河,只有一条船,船只能坐15个人,0 15人,只能等待下一条船的到来,于是30个人排成一队排队的位置即为他们的编号,从一开始报数数到九的人出列上传,如此循环,直到最终只剩下15人为止,问都有哪些编号的人上传了呢?分别采用列表和字典储存数据来求解

这不是约瑟夫环吗?链表的模板题
列表模拟链表:

n = 30
nodes = list(range(1, n+2))
nodes[n] = 1 
now = 1
while n > 15:
    for _ in range(8):
        prev, now = now, nodes[now]
    print(now, end=" ")
    nodes[prev] = nodes[now]
    now = nodes[prev]
    n -= 1

输出

9 18 27 6 16 26 7 19 30 12 24 8 22 5 23
  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/7581651
  • 这篇博客你也可以参考下:测试员,你该如何面对自己30岁后的下坡路?
  • 除此之外, 这篇博客: 人脸识别系统,未知人脸邮件发送中的 将电脑上的摄像头打开,像头像中的人脸与数据库中的人脸进行匹配,将在库中的人脸标示出来,不在库中的人脸报存下来,并给手机发送一封邮件提醒。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • #2 打开摄像头
    video_capture=cv2.VideoCapture(0)
    while True:
    
        ret,frame=video_capture.read()
        small_frame=cv2.resize(frame,(0,0),fx=0.25,fy=0.25)  #将照片缩小为四分之一,便于处理
        rgb_small_frame=small_frame[:,:,::-1]  #按照倒序将cv2的bgr转换为rgb
        face_locations=face_recognition.face_locations(rgb_small_frame)
        face_encodings=face_recognition.face_encodings(rgb_small_frame,face_locations)
    
        face_name_list=[]
        for face_encoding in face_encodings:
            matches=face_recognition.compare_faces(face_lib,face_encoding,tolerance=0.39)
            name='未知人员'
    
            if True in matches:
                first_match_index=matches.index(True)
                name=file_names[first_match_index][:-4]
                face_name_list.append(name)
    
        for (top,right,bottom,left),name in zip(face_locations,face_name_list):
            #还原图片大小
            top *= 4
            right *= 4
            bottom *= 4
            left *= 4
    
            cv2.rectangle(frame,(left,top),(right,bottom),(0,0,255),2)   #标注人脸信息
            img_PIL=Image.fromarray(cv2.cvtColor(frame,cv2.COLOR_BGR2RGB))
            font=ImageFont.truetype('simhei.ttf',40)
            draw=ImageDraw.Draw(img_PIL)
            draw.text((left+6,bottom-6),name,font=font,fill=(255,255,255))
            frame=cv2.cvtColor(np.asarray(img_PIL),cv2.COLOR_RGB2BGR)
            save_recorder(name,frame)
    
        cv2.imshow('window1',frame)
    
        if cv2.waitKey(1) &0xFF==ord('q'):   #1表示每一秒抓取一张照片用来识别
            break
    
    video_capture.release()
    
  • 您还可以看一下 吴刚老师的【吴刚】简历包装与面试技巧视频教程课程中的 30-图形、图像及文字在画面中的比例关系配置小节, 巩固相关知识点