当前位置:网站首页>Nlp-d57-nlp competition D26 & skimming questions D13 & reading papers & finding bugs for more than an hour

Nlp-d57-nlp competition D26 & skimming questions D13 & reading papers & finding bugs for more than an hour

2022-06-22 19:52:00 Zhen xiaopang

—— I finished three papers in the morning , Subconsciously open wechat to read , A few good books were added . Now I always feel that reading time is precious 、 Warm , I hope to leave a space for my heart , Maybe it's a green shade . Now it's time to brush the questions !

2816 Double pointer

 Insert picture description here

803 Interval merging

n = int(input())
a = []
res = []
for _ in range(n):
    a.append(list(map(int,input().split())))
res.append(a[0])
#  The interval merging algorithm needs to sort according to the value of the first point ,
#  Otherwise, the operation is as fierce as a tiger 
a.sort()
for i in range(1,n):
    if res[-1][1]>=a[i][0]:
        res[-1][1] = max(res[-1][1],a[i][1])
    else:
        res.append(a[i])

print(len(res))

Double linked list

look for bug It makes me feel sick
 Insert picture description here
I vomited. , For half an hour , No picture

m = int(input())
h,t = 0,1
r,l,e= [0]*100010,[0]*100010,[0]*100010
l[1]=0
r[0]=1
idx = 2


def add_to_k(x,k):
    global idx
    #  Insert... From the right 
    e[idx] =x
    l[idx] = k+1
    r[idx] = r[k+1]
    l[r[k+1]] = idx
    r[k+1] = idx
    idx+=1
    
def remove(k):
    r[l[k+1]] = r[k+1]
    l[r[k+1]]=l[k+1]

for _ in range(m):
    op,*pt = input().split()
    # *pt When taking value pt[0]
    if op=='L':
        add_to_k(int(pt[0]),0)
    elif op=='R':
        add_to_k(int(pt[0]),l[1])
    elif op=='D':
        remove(int(pt[0]))
    elif op=='IL':
        k,x = map(int,pt)
        add_to_k(x,l[k])
    else:
        k,x = map(int, pt)
        add_to_k(x,k)
#  First point to the first    
h =r[h]
while h!=1:
    # print(h)
    # print(2)
    print(e[h], end=' ')
    h = r[h]

A little bit , Still wrong

m = int(input())
h,t = 0,1
r,l,e= [0]*100010,[0]*100010,[0]*100010
l[1]=0
r[0]=1
idx = 2


def add_to_k(x,k):
    global idx
    #  Insert... From the right 
    e[idx] =x
    l[idx] = k+1
    r[idx] = r[k+1]
    l[r[k+1]] = idx
    r[k+1] = idx
    idx+=1
    
def remove(k):
    r[l[k+1]] = r[k+1]
    l[r[k+1]]=l[k+1]

for _ in range(m):
    op,*pt = input().split()
    # *pt When taking value pt[0]
    if op=='L':
        add_to_k(int(pt[0]),-1)
    elif op=='R':
        add_to_k(int(pt[0]),l[1])
    elif op=='D':
        remove(int(pt[0]))
    elif op=='IL':
        k,x = map(int,pt)
        add_to_k(x,l[k])
    else:
        k,x = map(int, pt)
        add_to_k(x,k)
#  First point to the first    
h =r[h]
print(r)
# print(l)
while h!=1:
    # print(h)
    # print(2)
    print(e[h], end=' ')
    h = r[h]

To give up , Write directly with the original idea , It's almost an hour .
hold k+1 Change it to k Just fine .
I feel like I still use k As a number , When you call a function later, you should consider the k Which number is better . Because the operation of the head node and the tail node is based on the number , If the function is defined as the number of insertions , It is difficult to convert the head and tail nodes . therefore ,k That is, the function parameter is still defined as idx Good numbering .

remember : Double linked list function k yes idx Number , The first k An insert , Its idx The number is k+1!!! remember !!

Start recording some common df Operation

df[‘’].value_counts()

Count the types and corresponding numbers of a column of values

原网站

版权声明
本文为[Zhen xiaopang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221803462338.html