拼多多 算法工程师-20180921

本文探讨了使用Python进行文本中单词频率统计的方法,并提供了一种优化缓存命中率的算法实现,通过调整缓存大小来提高缓存效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.数数看

import re
from collections import Counter
#i buy an apple watch from the aPple store, by the way I also like eating apple.
if __name__ == '__main__':
    duan=input()
    duan=duan.lower()
    wordlist=re.split('[!-\?,;:\.\s]',duan)
    words=[word for word in wordlist if word is not '']
    tongji=Counter(words)
    #print(tongji.most_common())    
    tongji_words = tongji.most_common()
    n=len(tongji_words)
    for i in range(n):
        if i==n-1 or tongji_words[i][1]!=tongji_words[i+1][1]:
            break
    most_cnt_words = tongji.most_common(i+1)
    res = [t[0] for t in most_cnt_words]
    res.sort()
    ans = " ".join(res)
    print(ans)

2.缓存问题

#include<stdio.h>
#include<stdlib.h>
#include<string.h> 
int add[10001];
int cun[1001];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&add[i]);
	}
	int res=-1;
	double max=0;
	for(int j=1;j<1000;j++){
		memset(cun,-1,sizeof(cun));
		int cnt=0;
		for(int i=0;i<n;i++){
			if(cun[add[i]%j]==add[i]){
				cnt++; 
			}
			else{
				cun[add[i]%j]=add[i];
			}
		}
		if(double(cnt)/double(n)>max){
			max=double(cnt)/double(n);
			res=j;
		}
	}
	printf("%d\n",res);
	//system("PAUSE");
} 
//0 1 1 0 2 3 2 3

3.优惠券问题

4.拆宝箱拿金币

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int M,A,R;
	cin >> M >> A >> R;
	vector<double> dp(A+R+1,0);
	dp[0]=1;
	for(int i=0;i<A;i++){
		for(int j=1;j<=R;j++){
			dp[i+j]=dp[i+j]+dp[i]/R;
		}
	}
	double res=0;
	for(int i=A;i<=M;i++){
		res+=dp[i];
	}
	printf("%.5f",res);
	return 0;
}

 

### 拼多多服务端研发工程师笔试相关信息 拼多多的服务端研发工程师笔试通常会考察候选人对计算机科学基础、算法设计与分析以及实际编程能力的掌握程度。以下是关于技术知识点、笔试题目和经验分享的具体内容。 #### 技术知识点 笔试中常见的技术知识点包括但不限于以下几个方面: - 数据结构:链表、栈、队列、树、图、哈希表等[^1]。 - 算法:排序算法(如快速排序、归并排序)、搜索算法(如深度优先搜索、广度优先搜索)、动态规划、贪心算法等[^1]。 - 计算机网络:HTTP协议、TCP/IP模型、DNS解析流程等。 - 操作系统:进程与线程、内存管理、文件系统、同步与互斥机制等[^1]。 - 数据库:SQL查询优化、索引原理、事务与隔离级别等[^1]。 #### 笔试题目示例 以下是一些可能出现在拼多多服务端研发工程师笔试中的题目类型: 1. **字符串处理** 编写一个函数,反转字符串中的每个单词,同时保持单词之间的顺序不变。 ```python def reverse_words(s: str) -> str: return ' '.join(word[::-1] for word in s.split()) ``` 2. **数组操作** 给定一个整数数组,找到其中两个数之和等于目标值的所有组合。 ```python def two_sum(nums: list, target: int) -> list: result = [] seen = {} for num in nums: complement = target - num if complement in seen: result.append([complement, num]) seen[num] = True return result ``` 3. **图算法** 实现一个函数,判断给定的无向图是否为二分图。 ```python from collections import deque def is_bipartite(graph: list) -> bool: n = len(graph) color = [0] * n # 0:未染色, 1:红色, -1:蓝色 queue = deque() for i in range(n): if color[i] == 0: queue.append(i) color[i] = 1 while queue: node = queue.popleft() for neighbor in graph[node]: if color[neighbor] == 0: color[neighbor] = -color[node] queue.append(neighbor) elif color[neighbor] == color[node]: return False return True ``` 4. **动态规划** 给定一组物品的重量和价值,以及背包的最大承重,求解能够装入背包的最大价值。 ```python def knapsack(weights: list, values: list, capacity: int) -> int: n = len(weights) dp = [0] * (capacity + 1) for i in range(n): for j in range(capacity, weights[i] - 1, -1): dp[j] = max(dp[j], dp[j - weights[i]] + values[i]) return dp[capacity] ``` #### 经验分享 在准备拼多多服务端研发工程师笔试时,可以参考以下几点建议: - 全面复习基础知识,尤其是数据结构与算法- 多做在线编程题,例如LeetCode、牛客网上的中等难度题目。 - 笔试时间有限,务必合理分配时间,确保每道题都有解答思路[^1]。 - 如果遇到不会的题目,尝试写出部分代码或列出解题步骤,以争取部分分数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值