通知:最新的秋招筆試編程題題目、思路以及參考代碼已經全部整理好放在【TechGuide】了,私信公眾號回復【美團】或者【百度】即可獲得最實時的筆試題解啦!
通知:最新的秋招筆試編程題題目、思路以及參考代碼已經全部整理好放在【TechGuide】了,私信公眾號回復【美團】或者【百度】即可獲得最實時的筆試題解啦!
通知:最新的秋招筆試編程題題目、思路以及參考代碼已經全部整理好放在【TechGuide】了,私信公眾號回復【美團】或者【百度】即可獲得最實時的筆試題解啦!
通知:最新的秋招筆試編程題題目、思路以及參考代碼已經全部整理好放在【TechGuide】了,私信公眾號回復【美團】或者【百度】即可獲得最實時的筆試題解啦!
【2021-09-04】美團秋招筆試五道編程題(附題目)
【2021-09-03】貝殼秋招筆試四道編程題(前三道ac)
【2021-09-01】阿里巴巴秋招筆試兩道編程題
【2021-09-01】華為秋招機試三道編程題(附題目,后兩題AC)
【2021-08-29】美團秋招筆試四道編程題
【2021-08-29】位元組跳動秋招筆試四道編程題
【2021-08-26】騰訊音樂秋招筆試編程三道題
【2021-08-25】華為秋招機試三道編程題
【2021-08-23】阿里巴巴秋招筆試兩道編程題
【2021-08-22】騰訊秋招筆試五道編程題
【2021-08-22】美團秋招筆試五道編程題(待更新)
【2021-08-21】網易秋招機試四道編程題(待更新)
【2021-08-14】榮耀秋招機試三道編程題(已更新)
【2021-08-18】華為秋招機試三道編程題(已更新)
【2021-08-18】阿里秋招筆試兩道編程題
【2021-08-15】美團秋招筆試五道編程題(已更新)
【2021-08-12】攜程秋招筆試三道編程題
【2021-08-11】華為秋招機試三道編程題(已更新)
【2021-08-09】阿里巴巴秋招筆試兩道編程題
【2021-08-08】拼多多秋招筆試四道編程題
【2021-08-08】美團秋招筆試五道編程題
【2021-08-08】好未來秋招三道編程題
【2021-08-07】網易互娛秋招筆試三道編程題
【2021-08-04】華為秋招兩道編程題
文章目錄
- 第一道:小M的多任務下載器
- 題目描述
- 參考代碼
- 第二道:尋找對稱的二叉樹特定節點(100%)
- 題目描述
- 參考代碼:
- 第三道:進攻防御(100%)
- 題目描述
- 參考代碼
- CPP版本
- 第四道:陣列游戲(100%)
- 題目描述
- 參考代碼
- CPP版本
第一道:小M的多任務下載器
題目描述
小M的程式設計大作業是撰寫一個多任務下載器,在做到計算任務并發數的時候遇到了困難,
在一次下載中,總共包含N個任務,每個任務會在第x秒開始、并持續y秒,小M想要知道,在一次下載中,同時最多會有多少個任務正在下載,
輸入描述
第一行輸入一個正整數N,代表總共有N個任務
之后共N行,每行包含兩個正整數x、y,x代表任務開始的時間,y代表任務的持續時間,
2
1 2
2 3
輸出描述
輸出包含一個整數,代表最高的任務并發數
2
解釋
第一個任務在第一秒開始,持續兩秒;第二個任務在第二秒開始,持續三秒,故在第二秒時有兩個任務同時在進行,最大并發數為2,
參考代碼
可以參考力扣會議室II
bool cmp(pair<int,int> const&a, pair<int, int> const& b) {
return a.first < b.first || a.first == b.first && a.second < b.second;
}
int main()
{
int n;
cin >> n;
vector<pair<int, int>> f;
f.reserve(2 * n);
for (int i = 0; i < n; i++) {
int x, y;
scanf_s("%d%d", &x, &y);
f.emplace_back(x, 1);
f.emplace_back(x+y, -1);
}
sort(f.begin(), f.end(), cmp);
int res = 0;
int m = 0;
for (auto const& i : f) {
m += i.second;
res = max(res, m);
}
cout << res << endl;
}
// 關注TechGuide! 大廠筆經面經閃電速遞!
第二道:尋找對稱的二叉樹特定節點(100%)
題目描述
給定一顆二叉樹,二叉樹每個節點都有一個唯一的整數值代表節點,在遍歷時,我們使用節點的整數值作為標記;結構對稱,是指二叉樹從根節點往下看,左右翻轉一下,能夠重合(不考慮節點內容比較,僅僅是結構),我們就稱這棵二又樹樹結構對稱
輸入:二叉樹的節點個數N(0<N<60000)、前序和中序遍歷結果,分別是第一行、第二行與第三行;各個節點整數值在1到60000之間
,
輸出:判斷這棵二叉樹是否結構對稱,若對稱請輸出最大值節點在樹中對稱節點的整數值,不對稱請直接輸出最大值節點的整數值
輸入描述
二叉樹的前序和中序 遍歷結果,以陣列序串列示
第一行為節點個數N(0<N<60000)前序和中序 遍歷結果,輸入分別是第二行與第三行
3
1 3 4
3 1 4
輸出描述
判斷這棵二叉樹是否結構對稱,若對稱請輸出最大值節點在樹中對稱節點的整數值,不對稱請直接輸出最大值節點的整數值
3
解釋
這顆二叉樹根是1,左右子節點分別是3和4,是結構對稱的,4是最大值節點,其對稱節點是3,所以最后輸出為3
參考代碼:
import java.util.*;
public class zj_2021_02 {
static HashMap<Integer, Integer> inorder_idx;
static int[] preorder;
static int[] inorder;
static int[] inorder_height;
static int max_idx = 0;
static int n;
static boolean flag = true;
public static void isMirror (int preorder_left, int preorder_right, int inorder_left, int inorder_right, int height) {
if (preorder_left > preorder_right || inorder_left > inorder_right) {
return;
}
int inorder_root = inorder_idx.get(preorder[preorder_left]);
inorder_height[inorder_root] = height;
int other_height = inorder_height[n - 1 - inorder_root];
if (!flag || (other_height != 0 && other_height != height)) {
flag = false;
return;
}
int left_size = inorder_root - inorder_left;
isMirror(preorder_left + 1, preorder_left + left_size, inorder_left, inorder_root - 1, height + 1);
isMirror(preorder_left + left_size + 1, preorder_right, inorder_root + 1, inorder_right, height + 1);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
preorder = new int[n];
inorder = new int[n];
inorder_height = new int[n];
for (int i = 0; i < n; i++) {
preorder[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
inorder[i] = sc.nextInt();
max_idx = inorder[i] > inorder[max_idx] ? i : max_idx;
}
inorder_idx = new HashMap<Integer, Integer>();
for (int i = 0; i < inorder.length; i++) {
inorder_idx.put(inorder[i], i);
}
isMirror(0, n - 1, 0, n - 1, 0);
System.out.println(flag ? inorder[n - 1- max_idx] : inorder[max_idx]);
}
}
// 關注TechGuide! 大廠筆經面經閃電速遞!
第三道:進攻防御(100%)
題目描述
一個陣列ai表示防御值,一個陣列bi表示進攻值,ai的乘積能被bi的乘積整除,輸出yes,反之輸出no,
思路就是質因數分解, 一個數大于另一個數 那么這個數的質因數分解的冪大于等于另一個數質因數分解的冪
參考代碼
CPP版本
public boolean f3(int[] a, int[] b) {
//題目給的不算大,可以用陣列,陣列放不下可以用 Map
int[] s = new int[100000];
for(int t : a) {
for(int i= 2; i<= t; i++){
while(t % i == 0){
s[i]++;
t/=i;
}
if(t > 1) s[t]++;
}
}
for(int t : b) {
for(int i= 2;i <= t; i++) {
while(t % i ==0){
s[i]--;
if(s[i] < 0 peturn false;
t/=i;
}
if(t>1){
s[t]--;
if(s[t]< 0) return false;
}
return true;
}
// 關注TechGuide! 大廠筆經面經閃電速遞!
第四道:陣列游戲(100%)
題目描述
雙休在家的凱凱真的是太無聊了,他準備和他家的貓玩一個游戲,
凱凱在小黑板上寫下一串有正有負的數列,貓咪從左到右,每碰到一個數,可以選擇選取或者不選取,在選取程序中,要保證所有選取的數的和始終為非負,在這個限制條件下求最多可以選取多少個數,小貓咪表示“我太難了”
你能幫幫它么?
輸入描述
會有多組詢問
首先輸入一個數字t(1<=t<=10)接下來有t組資料
每組資料里,首先會有一個數n,表示接下來這個數列的長度為n
然后接下來一行會有n個數字,從左到右表示題目所說的數列,
2
6
4 -4 1 -3 1 -3
5
1 2 3 4 5
輸出描述
對于每一個提問,請依次輸出正確的答案
5
5
解釋
第一組資料:選取第1,3,4,5,6個數第二組資料:因為全部是正數,所以全取,
參考代碼
CPP版本
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
// 4 -4 1 -3 1 -3
int f(vector<int>&nums) {
int sum = 0;
int ans = 0;
queue<int> que;
for (int z : nums) {
if (sum + z >= 0) {
ans++;
sum += z;
if (z < 0) que.push(z);
}
else {
if (!que.empty() && z > que.front()){
sum -= que.front();
sum += z;
que.pop();
que.push(z);
}
}
}
return ans;
}
int main()
{
int t;
cin >> t;
vector<int> vec;
vector<vector<int>> vvint;
while (t--)
{
int n;
cin >> n;
while (n--)
{
int k;
cin >> k;
vec.push_back(k);
}
vvint.push_back(vec);
vec.clear();
}
for (int i = 0; i < vvint.size(); i++) {
cout << f(vvint[i]) << endl;
}
return 0;
}
// 關注TechGuide! 大廠筆經面經閃電速遞!
關注TechGuide,大廠筆經面經閃電速遞!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/300070.html
標籤:其他
上一篇:React官網入門專案井字棋游戲

