Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

请大佬留下代码,下面是写的代码,但是有错,有没有知道错哪里的大佬,或者有没有更简约的,展示一下,谢谢大佬

6e40ef91be723cef79d257266ad888c.jpg5692d594fab85776f42bca6edab8aa8.jpg167c941bc0a305c1a3577c64d1791e3.jpg

import?sys
import?re

class?Node:
????def?__init__(self,data?=?None,?next?=?None):
????????self.data?=?data
????????self.next?=?next

class?Queue:
????def?__init__(self):
????????self.head?=?Node()
????????self.tail?=?self.head

????def?put(self,n):
????????self.tail.next?=?Node(n)
????????self.tail?=?self.tail.next

????def?get(self):
????????return?self.head.next.data

????def?delete(self):
????????g?=?self.head
????????g.next?=?g.next.next
????????if?g.next==None:
????????????self.tail?=?g

def?funcname():
????s?=?sys.stdin.readline()
????r?=?re.findall(r'd+',?s)
????bridgelength?=?int(r[0])
????bridgeload?=?int(r[1])
????br?=?Queue()
????num?=?1
????sw?=?0
????sl?=?0

????while?True:
????????s?=?sys.stdin.readline()
????????if?s=="":
????????????break
????????r?=?re.findall(r'd+',?s)
????????for?i?in?range(0,len(r),2):
????????????l?=?int(r[i])
????????????w?=?int(r[i+1])
????????????sw?+=?w
????????????sl?+=?l
????????????br.put([num,l,w])
????????????while?sl-br.get()[1]?>=?bridgelength:
????????????????t?=?br.get()
????????????????sl?-=?t[1]
????????????????sw?-=?t[2]
????????????????br.delete()
????????????if?sw>bridgeload:
????????????????print(br.get()[0])
????????????????return
????????????num?+=?1
????print(-1)

funcname()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...