首页 > 其他分享 >HJ64_MP3光标位置_数组_模拟思路_滑动窗口

HJ64_MP3光标位置_数组_模拟思路_滑动窗口

时间:2023-04-05 14:16:43浏览次数:52  
标签:index right 10 HJ64 sys MP3 歌曲 光标 left

思路:用模拟跟踪U、D 得输出的歌曲,用双指针跟踪歌曲当前窗口。

注意,在第一首向上滑动,和最后一首向下滑是,窗口特殊跳动,此时双指针指向特殊处理。

留意到,不管是特殊情况还是普通情况,指针上划时歌曲减一。如1调到10,10上划为9,视为减一。

得到代码如下:

import sys
a = int(sys.stdin.readline().strip())
b=sys.stdin.readline().strip()
#a = 10
#b='UUUU'
left,right=0,4
index=1#标记歌曲第几首
for i in b:
    if i=="U":
        if index==1:
            left=a-3
            right=a+1
            index=a
        else:
            index-=1
        #print("U",index)
    elif i == "D":
        if index==a:
            left=1
            right=5
            index=1
        else:
            index+=1   
        #print("D",index)
    if index not in range(left,right):
        if index<left:
            left-=1
            right-=1
            #print("U",left,right)
        else:
            left+=1
            right+=1
            #print("D",left,right)
if a<=4:
    left=1
    right=a+1
print(" ".join(list(map(str,range(left,right)))))
print(index)

 

标签:index,right,10,HJ64,sys,MP3,歌曲,光标,left
From: https://www.cnblogs.com/tanyuanqing/p/17289335.html

相关文章

  • COMP3411/9814 人工智能
    COMP3411/9814ArtificialIntelligenceTerm1,2023Assignment3–PlanningandMachineLearningDue:Week10-10pmFriday21AprilMarks:10%offinalassessmentforCOMP3411/9814ArtificialIntelligenceQuestion1:Planning(4marks)Modifythesimpleplanner......
  • COMP3357 Exercise
    老师今天特意强调了考试,并且讲解了这些题,让人很难不怀疑......!!在这里每道题都认真研究一下,做个记录RSAAdaptedRSAwithCRT(a)很明显,就不多赘述了(b)由于\(g_1=g^{r_1(p-1)}\)有\(g_1\equivg^{r_1(p-1)}\pmod(p)\),根据费马小定理,\(g_1\equiv1\pmod{p}\),即\(g_1......
  • python把mp4转mp3
    预先下载Pipinstallmoviepyfrommoviepy.editorimport*defoutputmp3(input_path,output_path):listdir=os.listdir(input_path)#获得路径所有文件名mp4namelist=[namefornameinlistdirifname.endswith('.mp4')]#筛选出所有MP4forfil......
  • Multimedia (MP3, MPEG-4, AVI, DiVX, etc.) support in Ubuntu 12.04 (Precise)
    Whydoesn’tUbuntusupportMP3‘outofthebox’?UbuntucannotincludesupportforMP3orDVDvideoplaybackorrecording.MP3formatsarepatented,andthepatentholdershavenotprovidedthenecessarylicenses.Ubuntualsoexcludesothermultimediasof......
  • 在input输入框光标位置插入内容
    letinput=document.getElementById('input')lettextToInsert='我是插入的内容';letstartPosition=input.selectionStart;letendPosition=input.selectionEnd;input.value=input.value.substring(0,startPosition)+textToInsert+input.val......
  • IDEA取消左键点击空白处时的光标跟随
      没有位于文末   ......
  • Typora修改代码块光标颜色
    使用Ctrl+Shift+k或者```生成代码块:打开Typora,按shift+F12,打开开发者人员工具。打开base.user.css文件,找到对应的样式,修改并重新打开Typora即可:......
  • COMP30024 Artificial Intelligence
    ProjectPartASinglePlayerInfexionCOMP30024ArtificialIntelligenceMarch2023OverviewInthisfirstpartoftheproject,youwillwriteaprogramtoplayasi......
  • COMP3121/9101 23T1难点分析
    COMP3121/910123T1—Assignment2(UNSWSydney)DueMonday27thMarchat5pmSydneytimeInthisassignmentweapplythegreedymethodandassociatedgraphalgo......
  • COMP3221 Routing Algorithm
    Due:March31st,2023(Friday,Week6)by11:59PMCOMP3221Assignment1:RoutingAlgorithmThegoalofthisassignmentistoimplementroutingprotocolsforane......