秋招 8.24京东笔试 JDS-2025届秋招-后端开发工程师-第3批

8.24 JDS-2025届秋招-后端开发工程师-第3批

前言

京东不同的语言(C++, Java, Go)卷子是不同的,一开始会让你选对应的语言。

选择题分为八股文和编程逻辑题,编程大题有三题(15, 20, 25)

大题,笔者AC了前两道,最后一题暴力20%

希望可以进面!

1、

输入只一个n(-10100 <= n <= 10100),输出0 ~ n有多少个数是100的倍数。

知识点:库函数的使用

c 复制代码
#include<bits/stdc++.h>
using namespace std;
/*#define int long long*/
#define endl '\n'
#define P pair<int, int>
#define x first
#define y second
const int maxl = 1e6 + 7;

string s;

void slove() {
    cin >> s;
    if (s[0] == '-' || s.size() < 3) cout << 0;
    else {
        cout << s.substr(0, s.size() - 2) << endl; 
    }
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    /*cin >> t;*/
    while(t--) slove();
    return 0;
}

2

一个n * m的矩阵,有k次询问,每次询问包含 op, x, y。

op为字符c, 把(x, y)位置变成黑色

op为字符r, 输出(x, y)位置右边第一个白色方格位置的坐标。

op为字符l, 输出(x, y)位置左边第一个白色方格位置的坐标。

op为字符u, 输出(x, y)位置上边第一个白色方格位置的坐标。

op为字符d(反正是最后一种操作,具体啥字符我忘了), 输出(x, y)位置下边第一个白色方格位置的坐标。

知识点:模拟

c 复制代码
#include<bits/stdc++.h>
using namespace std;
/*#define int long long*/
#define endl '\n'
#define P pair<int, int>
#define x first
#define y second
const int maxl = 1e2 + 7;

int n, m, k;
int G[maxl][maxl];
void slove() {
    cin >> n >> m >> k;
    while (k--) {
        char op;
        int x, y;
        cin >> op >> x >> y;
        if (op == 'c') G[x][y] = 1;
        else if (op == 'l') {
            bool flag = 0;
            while (--y > 0) {
                if (!G[x][y]) {
                    cout << x << " " << y << endl;
                    flag = 1;
                    break;
                }
            }
            if (!flag) cout << -1 << endl;
        } else if (op == 'r') {
            bool flag = 0;
            while (++y <= m) {
                if (!G[x][y]) {
                    cout << x << " " << y << endl;
                    flag = 1;
                    break;
                }
            }
            if (!flag) cout << -1 << endl;
        } else if (op == 'u') {
            bool flag = 0;
            while (--x > 0) {
                if (!G[x][y]) {
                    cout << x << " " << y << endl;
                    flag = 1;
                    break;
                }
            }
            if (!flag) cout << -1 << endl;
        } else {
            bool flag = 0;
            while (++x <= n) {
                if (!G[x][y]) {
                    cout << x << " " << y << endl;
                    flag = 1;
                    break;
                }
            }
            if (!flag) cout << -1 << endl;
        }
    }   
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    /*cin >> t;*/
    while(t--) slove();
    return 0;
}

3

有n根木棍排成一列,第i根木棍的长度为a;。

请你从中选出一个最长的子区间,使得区间内任意三根木棍都能构成三角形。只需要输出选出的区间端点即可。I输入描述

第一行一个整数n(3≤n≤106) , 表示木棍的数量。

第二行n个整数,第i个整数a;(1≤a;≤109)表示第i根木棍的长度。

输出描述

输出一行两个整数,表示最长的满足条件的区间的两个端点,如果有多个满足条件的区间,输出左端点最小的区间。保证答案存在。

示例

输入

3

1 2 3

输出

1 2

输入

9

2 3 3 3 1 1 3 3 3

输出

1 4

最初的暴力过20%,被我搞丢了,但是这个应该比我原来的更优秀,但是最后一秒没交上去,大家看看对不对。

c 复制代码
#include <algorithm>
#include<bits/stdc++.h>
#include <climits>
using namespace std;
#define int long long
#define endl '\n'
#define P pair<int, int>
#define x first
#define y second
const int maxl = 1e6 + 7;
struct node {
    int l;
    int r;
    int len;
};

int n;
int a[maxl];
node ans;
map<int, int> mp;

void slove() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    int minn, maxn;
    for (int l = 1, r = 1; r <= n; r++) {
        mp[a[r]]++;

        minn = mp.begin()->first;
        maxn = mp.end()->first;
        while (2 * minn <= maxn) {
            if (!--mp[a[l]]) mp.erase(a[l]);
            l++;
            minn = mp.begin()->first;
            maxn = mp.end()->first;
        }

        if (2 * minn > maxn && ans.len < r - l + 1) {
            ans.l = l;
            ans.r = r;
            ans.len = r - l + 1;
        }
        /*cout << "l:" << l << " r:" << r << endl;*/
        /*for (auto [k, v] : mp) cout << "k-->" << k << " v-->" << v << endl;*/
        /*cout << endl;*/
    }
    cout << ans.l << " " << ans.r << endl;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    /*cin >> t;*/
    while(t--) slove();
    return 0;
}

下面是我根据网友思路写的双指针加滑动窗口,友友们可以一起讨论对不对。

c 复制代码
#include <algorithm>
#include<bits/stdc++.h>
#include <deque>
using namespace std;
/*#define int long long*/
#define endl '\n'
#define P pair<int, int>
#define x first
#define y second
const int maxl = 1e6 + 7;
struct node {
    int l;
    int r;
    int len;
};

int n;
int a[maxl];
node ans;
deque<int> min_dq, max_dq;

void slove() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int l = 1, r = 1; r <= n; r++) {
        while (!max_dq.empty() && a[max_dq.back()] < a[r]) max_dq.pop_back();
        while (!min_dq.empty() && a[min_dq.back()] > a[r]) min_dq.pop_back();
        max_dq.push_back(r);
        min_dq.push_back(r);

        while (!max_dq.empty() && !min_dq.empty() && 2 * a[min_dq.front()] <= a[max_dq.front()]) {
            l++;
            if (max_dq.front() < l) max_dq.pop_front();
            if (min_dq.front() < l) min_dq.pop_front();
        }

        if (ans.len < r - l + 1) {
            ans.l = l;
            ans.r = r;
            ans.len = r - l + 1;
        }
    }

    if (ans.len <= 2) cout << 1 << " " << 2 << endl;
    else cout << ans.l << " " << ans.r << endl;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    /*cin >> t;*/
    while(t--) slove();
    return 0;
}
相关推荐
一定要AK几秒前
萌新赛练习
数据结构
津津有味道6 分钟前
Qt C++串口SerialPort通讯发送指令读写NFC M1卡
linux·c++·qt·串口通信·serial·m1·nfc
傅里叶的耶33 分钟前
C++系列(二):告别低效循环!选择、循环、跳转原理与优化实战全解析
c++·visual studio
Vitta_U1 小时前
MFC的List Control自适应主界面大小
c++·list·mfc
Dovis(誓平步青云)2 小时前
基于探索C++特殊容器类型:容器适配器+底层实现原理
开发语言·c++·queue·适配器·stack
Gyoku Mint2 小时前
深度学习×第4卷:Pytorch实战——她第一次用张量去拟合你的轨迹
人工智能·pytorch·python·深度学习·神经网络·算法·聚类
葫三生3 小时前
如何评价《论三生原理》在科技界的地位?
人工智能·算法·机器学习·数学建模·量子计算
pipip.3 小时前
UDP————套接字socket
linux·网络·c++·网络协议·udp
拓端研究室5 小时前
视频讲解:门槛效应模型Threshold Effect分析数字金融指数与消费结构数据
前端·算法
随缘而动,随遇而安7 小时前
第八十八篇 大数据中的递归算法:从俄罗斯套娃到分布式计算的奇妙之旅
大数据·数据结构·算法