中望笔试不简单(1h)


1. 虚函数表是数组还是指针
2. auto 能不能作为返回类型、函数参数,auto 定义的变量一定要初始化
3. int 的基本运算符能不能重载,运算符重载能不能改变运算符的优先级
4. 考了模板的传入参数能不能为数据类型
5. 是否优先加载const类型的用户自定义类型函数参数(没看懂)
6. . $ @ 不能重载吗
7. 识别地址表示
8. delete new malloc free。malloc不会返回异常
9. 智能指针 unique 不能拷贝,weak 不会改变计数
10. 微信在接受和发送消息时进程会阻塞吗?互斥?就绪
11. 用单链表实现栈,问入栈的语句
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};*/

// 1. 检测是否为平衡树
class Balance {
//     map<TreeNode*,int> h;
    bool is;
    int getHeight(TreeNode* root){
        if(!is) return 0;
        int lh=0,rh=0;
        if(root->left){
            lh=getHeight(root->left);
//             h[root->left]=lh;
        }
        if(root->right){
            rh=getHeight(root->right);
//             h[root->right]=rh;
        }
//         h[root]=max(lh,rh)+1;
        if(abs(lh-rh)>1){
            is=false;
        }
        return max(lh,rh)+1;
    }
public:
    bool isBalance(TreeNode* root) {
        // write code here
        if(!root) return true;
        is=true;
        getHeight(root);
        return is;
    }
};

// 求最大能装的单位数  83.3%
// 给出 n 类箱子,给出每类箱子的个数、每类箱子一个能装多少单位
// 一共能装 truckSize 个箱子
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param boxArray int整型vector<vector<>> 箱子
     * @param boxTypesSize int整型 箱子类型数量
     * @param truckSize int整型 卡车容纳箱子数
     * @return int整型
     */
    int maximumUnits(vector<vector<int> >& ba, int bts, int ts) {
        // write code here
        sort(ba.begin(),ba.end(),[](auto a,auto b){return a[1]>b[1];});
        int i=0;
        int ans=0;
        while(ts>0&&i<ba.size()){
            if(ts>ba[i][0]){
                ans+=ba[i][0]*ba[i][1];
                ts-=ba[i][0];
                i++;
            }else{
                ans+=ts*ba[i][1];
                ts=0;
            }
        }
        return ans;
    }
};

// 83.3%
https://leetcode.cn/problems/maximum-units-on-a-truck/submissions/

力扣过了但笔试只83.3%  // 检测某个点是否在某个区域内
// 如果在区域内或者在边上,返回到区域顶点的最大距离
// 如果在区域外或者在顶点上,返回到区域顶点的最小距离
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param point double浮点型vector 鸟儿落地的坐标
     * @param array double浮点型vector<vector<>> 桩的坐标
     * @return double浮点型
     */
    
    
    double distance(vector<double>& p, vector<vector<double> >& a) {
        // write code here
        double x=p[0], y=p[1];
        int n = a.size();
        for(const auto& i:a){
            if(i[0]==x&&i[1]==y)
                return 0.0;
        }
        double maxDis=0, minDis=0x0fffffff;
        for(const auto& i:a){
            double dis=sqrt((i[0]-x)*(i[0]-x)+(i[1]-y)*(i[1]-y));
            maxDis = max(dis, maxDis);
            minDis = min(dis, minDis);
        }
        bool in = true;
        sort(a.begin(),a.end());
        if(x<a[0][0]||x>a[n-1][0])
            in = false;
        return in ? maxDis : minDis;
    }
};


#中望软件校招##中望龙腾#
全部评论
不太明白第三题应该咋做
1 回复 分享
发布于 2022-07-29 20:39
什么模式acm?
2 回复 分享
发布于 2022-07-28 23:55
似乎遇到一模一样的题)
1 回复 分享
发布于 2022-08-01 00:08
相信自己,你可以的有兴趣的话可以投一下荣耀,八月起开始简历筛选,内推码:yuhvad 网址https://career.hihonor.com/SU60eea919bef57c1023f6fe78/pb/school.html
点赞 回复 分享
发布于 2022-07-28 23:08
卡车装箱子lc1710
点赞 回复 分享
发布于 2022-08-06 16:03
怎么判断鸟在不在范围里面的啊
点赞 回复 分享
发布于 2022-08-19 00:49 广东

相关推荐

2024-12-23 10:55
已编辑
大连理工大学 Java
牛客930504082号:华子综测不好好填会挂的,而且填的时候要偏向牛马选项
点赞 评论 收藏
分享
Cassifa:发的字比你都多的一律视为骗子或者想白嫖压榨实习生的
点赞 评论 收藏
分享
评论
13
118
分享

创作者周榜

更多
牛客网
牛客企业服务