当前位置:网站首页>Meituan machine test in 2022
Meituan machine test in 2022
2022-07-01 09:00:00 【disconnect_ mind】
evaluation
Overall speaking , Less difficult than other companies , Multiple choice questions only 3 topic , It's all machine learning , And there is a problem , Semi supervision is taken from textbooks .
Programming problems 4 The overall difficulty of Tao is not high , I don't know what to do ,AC 了 72%, Everything else passed .
Programming questions
subject 1
n Number , find [k-1,k+1] The number of digits contained in the interval with the largest number of digits in the range .
Input n, Second line input n Number , Each number range is 1-100.
Example
6
1 2 2 3 5 5
Output
4
Code
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main(){
int n;
cin >> n;
//vector<int> arr;
map<int, int> counts;
int minVal = 100, maxVal = 0;
for(int i = 0; i < n; i++){
int value;
cin >> value;
counts[value]++;
if(value > maxVal) maxVal = value;
if(value < minVal) minVal = value;
}
int res = 0;// minVal = arr[0], maxVal = arr[n - 1]
for(int cur = minVal; cur < maxVal; cur++){
int tempcount = counts[cur-1] + counts[cur] + counts[cur+1];
res = max(tempcount, res);
}
cout << res;
}
subject 2
from (0,0) To (n,m), Try to walk 'o' Way , Can only move down and right , The calculation needs to go through at least a few 'x'. The essence is 《 The finger of the sword offer》13 be similar .
Example
5 5
oxxxx
xxoox
oooxo
xxxxo
ooooo
Output
2
Code
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main(){
int m,n;
cin >> n >> m;
vector<vector<int>> weight(n, vector<int>(m, 0));
char c;
for(int i = 0; i < n; i++){
for(int j = 0; j < m;j++){
cin >> c;
if(c == 'x') weight[i][j] = 1;
}
}
vector<vector<int>> sum(n, vector<int>(m, 50000));
sum[0][0] = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m;j++){
if(i > 0) sum[i][j] = min(sum[i][j], sum[i-1][j] + weight[i-1][j]);
if(j > 0) sum[i][j] = min(sum[i][j], sum[i][j-1] + weight[i][j-1]);
}
}
cout << sum[n-1][m-1];
}
subject 3
The essence is to replace letters to maximize the length of consecutive characters leetcode 424, Similar problems have appeared in other companies .
Example
10 2
--++--+++-
Output
7
Code
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main(){
int n,k;
cin >> n >> k;
string str;
cin >> str;
int i = 0, ans = 0;
while(i <= n-k){
int x = k, j = i + 1;
while(j < n){
if(str[i] != str[j]){
if(x == 0) break;
x--;
}
j++;
}
ans = min(n, max(ans, j-i+x));
i++;
while(i<n && str[i-1]==str[i]) i++;
}
cout << ans;
}
subject 4
Two positive integers in the first line n and q,n Indicates the number of brands of milk tea ,q Represents the number of operations . The second line n Positive integers separated by spaces , Represents the unit price profit of each milk tea brand . Next q Operations , Each operation is one of the following :Add x y : brand x Increased sales of milk tea y.Query BestSales : Query the milk tea brands with the largest sales so far in the current operation , If not unique, output the smallest .Query BestProfit : Query the milk tea brands with the most profits so far , If not unique, output the smallest .1 <= n <= 100000, 1 <= q <= 500 Guarantee the brand x The scope of [1, n] within , Guaranteed sales y The added value is [1, 100] The answer to internal sales and profits is guaranteed to be [1, 1e9] Within the scope of
Example
2 6
1 2
Add 1 3
Add 2 2
Query BestSales
Query BestProfit
Add 1 1
Query BestProfit
Output
1
2
1
Code
AC 72%
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main(){
int n, q;
cin >> n >> q;
vector<int> profit(n);
for(int i = 0;i < n;i++)
cin >> profit[i];// The output brand number needs to be added 1
vector<int> totalSale(n), totalPro(n);
for(int i = 0; i < q; i++){
string query;
cin >> query;
if(query[0] == 'A'){
int brand, num;
cin >> brand >> num;// need -1
totalSale[brand - 1] += num;
totalPro[brand-1] += num * profit[brand-1];
}
else{
cin >> query;
if(query=="BestSales"){
int resSale = 0, resbrand = -1;
for(int i = 0;i <n;i++){
if(resSale< totalSale[i]){
resSale = totalSale[i];
resbrand = i;
}
}
cout<<resbrand + 1 << '\n';
}
else{
int resPro = 0, resbrand = -1;
for(int i = 0;i <n;i++){
if(resPro< totalPro[i]){
resPro = totalPro[i];
resbrand = i;
}
}
cout<<resbrand + 1 << '\n';
}
}
}
return 0;
}
边栏推荐
- 动态代理
- Embedded Engineer Interview Question 3 Hardware
- Shell脚本-read命令:读取从键盘输入的数据
- Nacos - 配置管理
- Shell script - special variables: shell $, $*, [email protected], $$$
- pcl_ Viewer command
- [MFC development (16)] tree control
- Understand shallow replication and deep replication through code examples
- Databinding source code analysis
- Jeecg restart alarm 40001
猜你喜欢
Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
Nacos - 配置管理
How to manage fixed assets well? Easy to point and move to provide intelligent solutions
Brief introduction to AES
Vsync+ triple cache mechanism +choreographer
个人装修笔记
Redis——Lettuce连接redis集群
19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
How to manage fixed assets efficiently in one stop?
Bird recognition app
随机推荐
yolov5训练可视化指标的含义
Shell脚本-case in语句
Computer tips
Programming with C language: calculate with formula: e ≈ 1+1/1+ 1/2! …+ 1/n!, Accuracy is 10-6
IT 技术电子书 收藏
钓鱼识别app
Nacos - Configuration Management
用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
Which method is good for the management of fixed assets of small and medium-sized enterprises?
R语言观察日志(part24)--初始化设置
Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling
Shell脚本-if else语句
Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
Redis——Lettuce连接redis集群
Advanced level of C language pointer (Part 1)
Flink面试题
Serialization, listening, custom annotation
How to solve the problem of fixed assets management and inventory?
It technology ebook collection
安装Oracle EE