腾讯笔试,数据分析岗位
1. 不会
2. 两段区间定积分, 线下测试没问题,提交0分
# -*- coding: utf-8 -*- import sys # sys.stdin = open('data') def func(A, B, C): delta = (B * C - A) ** 2 - (B*C)**2 if delta < 0: print(0) return up = A - B * C s1 = (up + delta ** 0.5) / (B * B) #交点1的坐标 s2 = (up - delta ** 0.5) / (B * B) #交点2的x坐标 if s1 > s2: s1, s2 = s2, s1 ans = 0 ans += 2 / (3 * A) * (2 * A * s1) ** 1.5 #第一段区间定积分 ans += 1 / (3 * A) * (( 2* A * s2) ** 1.5 - (2*A*s1)**1.5) #第二段区间定积分 ans -= B / 2 * (s2 * s2 - s1 * s1) ans -= C * (s2 - s1) print(ans) while True: try: n = int(input()) for i in range(n): A, B, C = map(int, input().split()) func(A, B, C) except: break3. 总数-不符合条件数, 超时, 过30%
mod = 100003 m, n = map(int, input().split()) x1 = m ** (n-1) x2 = (m-1) ** (n-1) print(m * (x1 - x2) % mod)4. 找到具有相反变化趋势的序列,例如(x1, x1+a, x1+b)与(x2, x2-a, x2-b)可以匹配成功, 只需记录(a, b)和(-a, -b)即可, AC
from collections import defaultdict n, k = map(int, input().split()) nums = [] dic = defaultdict(int) for i in range(n): x = list(map(int, input().split())) tmp = [] for j in range(len(x)-1): tmp.append(x[j+1]-x[j]) dic[tuple(tmp)] += 1 # print(dic) ans1 = ans2 = 0 first = True for x, cnt in dic.items(): tmp = tuple(-e for e in x) if tmp == x and first: # (0, 0, 0, 0, ...)的情况 ans2 = cnt * (cnt-1) // 2 first = False elif tmp in dic: ans1 += cnt * dic[tmp] print(ans1//2 + ans2)
from collections import defaultdict T = int(input()) for _ in range(T): #BFS广度优先遍历,以每个具有边连接的节点为起点 n = int(input()) graph = defaultdict(list) sts = [] for i in range(n): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) sts.append(a) ans = 1 # def dfs(graph, i, vis, count): # global ans # ans = max(ans, count) # for j in graph[i]: # vis.add(i) # dfs(graph, j, vis, count+1) vis = set() for i in sts: if i in vis:continue q = [i] prev_len = len(vis) vis.add(i) while q: x = q.pop(0) for xx in graph[x]: if not xx in vis: q.append(xx) vis.add(xx) ans = max(ans, len(vis)-prev_len) print(ans)