华为软件笔试

1.

n=int(input())
mn=[]
for i in range(n):
    aa=[]
    for j in range(2):
        line=int(input())
        aa.append(line)
    mn.append(aa)


def Last(n, m):
    if not n or not m:
        return -1
    lst = [i+1 for i in range(n)]
    i = 0
    res=[]
    while len(lst)>1:
        i = (m+i-1)%len(lst)
        k=lst.pop(i)
        res.append(k)
    res.append(lst[0])
    return res

for i in range(n):
    nn=mn[i][0]
    mm=mn[i][1]
    ww=Last(nn, mm)
#    print(ww)
    for j in ww[:-1]:
        print(j,end=' ')
    print(ww[-1])

2.

a, b = 10,10
lst = list(map(int, input().split(' ')))
bb = []
for i in range(a):
    line = lst[10*(i):10*(i+1)]
    bb.append(line)

class Solution:
    def __init__(self, pos):
        self.pos = pos
        self.cnt = 0 
        self.dp = []  

    def dfs(self, i, j):
        if 0 <= i < a and 0 <= j < b:
            if self.pos[i][j] == 1:
                self.cnt += 1
                self.pos[i][j] = 0  
                self.dfs(i - 1, j)
                self.dfs(i + 1, j)
                self.dfs(i, j - 1)
                self.dfs(i, j + 1)

    def func(self):
        for i in range(a):
            for j in range(b):
                if self.pos[i][j] == 1:
                    self.cnt = 0 
                    self.dfs(i, j)  
                    if self.cnt > 0:
                        self.dp.append(self.cnt)
        return max(self.dp)

s = Solution(bb)
m = s.func()
print(m)

3.

n = int(input().strip())
aa = [int(x) for x in input().strip().split()]
 
def huiwenxulie(aa, l, r):
    t=0
    left = aa[l]
    right = aa[r]
    while (l<r):
        if left<right:
            l+=1
            left+=aa[l]
            t+=1
            continue
        elif left>right:
            r-=1
            right+=aa[r]
            t+=1
            continue
        elif left==right:
            l+=1
            r-=1
            left = aa[l]
            right = aa[r]
    return t
 
print (huiwenxulie(aa,0,n-1))

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值