第十七周:[Sicily]机考模拟题1000-1006

【华为机试真题Python】从入门到入职-真题列表导读 华为机试有三道题目,第一道和第二道属于简单或中等题,分值为100分,第三道为中等或困难题,分值为200分。总分为400分,150分钟考试时间。之前通过为150分,现在好像分数提高了,大家不要太大意,一定要多刷题,争取拿高分,毕竟分数越高评级越高,工资也就越高。OD的工资待遇还是很可观的15K-30K*14-16,希望大家努力(肺腑之言)本专栏有100+道题(持续更新中),都是往期的HW机试真题,根据过往同学的经验基本都会考到原题。大家有什么不懂的都可以留言。真题列表(持续更新中) 阅读详情

1000.函数求值:直接暴力模拟即可。


class Solution {
public:
    int F(int k, int n) {
      int ans[15][15] = {0};
      int i,j,kk,cur;
      for(i = 0;i <= n;i++)
          ans[0][i] = i;
      for(i = 1;i <= k;i++){
        for(j = 1;j <= n;j++){
            cur = 0;
            for(kk = 1;kk <= j;kk++)
                cur += ans[i - 1][kk];
            ans[i][j] = cur;
        }
      }
      return ans[k][n];
    }
};             

1001.会议安排:分别对A、B两个数组降序排序,然后对两个数组从头依次进行匹配,有点类似于贪心。


class Solution {
public:
    int assignConferenceRoom(vector<int>& A, vector<int>& B) {
    sort(A.begin(),A.end(),greater<int>());
    sort(B.begin(),B.end(),greater<int>());
    int ans = 0;
    vector<int>::iterator itra = A.begin();
    vector<int>::iterator itrb = B.begin();
    while (itra != A.end() && itrb != B.end()) {
        if(*itra <= *itrb){
            ans ++;
            itrb ++;
        }
        itra ++;
    }
    return ans;  
    }
};                

1002.等价二叉树:递归判断。


class Solution {
public:
   bool isEqual(TreeNode* p, TreeNode* q) {
           if(p == NULL && q == NULL)
               return true;
           if(p == NULL || q == NULL)
               return false;
           return (p->val == q->val)&&isEqual(p->left,q->left) && isEqual(p->right,q->right);
    }
};      

1003.相连的1:BFS。


class Solution {
public:
    int countConnectedOnes(vector<vector<char>>& A){
    int ans = 0,i,j;
    bool found = true;
    vector<vector<bool>> visited(A.size(),vector<bool>(A[0].size(),false));
    while(found){
        found = false;
        for(i = 0;i < A.size();i++)
            for(j = 0;j < A[0].size();j++){
                if(A[i][j] == '1' && !visited[i][j]{
                    found = true;
                    queue<pair<int,int>> q;
                    q.push(pair<int, int>(i,j));
                    visited[i][j] = true;
                    int x[4] = {-1,1,0,0};
                    int y[4] = {0,0,-1,1};
                    while(!q.empty()){
                     pair<int, int> cur = q.front();
                        q.pop();
                        for(int ii = 0;ii < 4;ii++)
                            if(cur.first + y[ii] < A.size() && cur.first + y[ii] >= 0 && cur.second + x[ii] < A[0].size() && cur.second + x[ii] >= 0)
                            if(!visited[cur.first + y[ii]][cur.second + x[ii]] && A[cur.first + y[ii]][cur.second + x[ii]] == '1'){
         q.push(pair<int, int>(cur.first + y[ii],cur.second + x[ii]));
                                    visited[cur.first + y[ii]][cur.second + x[ii]] = true;}
          }
    ans ++;
         }
         }
     }
    return ans;            
    }
};                                 

1004.无环图:拓扑排序。


class Solution {
public:
       bool isDAG(int n, vector<pair<int, int>>& edges) {
          vector<int> out(n,0);
    vector<vector<int>> in(n,vector<int>());
    vector<pair<int, int>>::iterator itr = edges.begin();
    while(itr != edges.end()){
        out[(*itr).first] ++;
        in[(*itr).second].push_back((*itr).first);
        itr++;
    }
    bool found_out_0 = true;
    vector<bool> visited(n,false);
    while(found_out_0){
        found_out_0 = false;
        for(int i = 0;i < out.size();i++)
            if(out[i] == 0 && visited[i] == false){
                found_out_0 = true;
                visited[i] = true;
                for(int j = 0;j < in[i].size();j++)
                    out[in[i][j]]--;
            }
    }
    for(vector<bool>::iterator itr = visited.begin();itr != visited.end();itr++)
        if(*itr == false)
            return false;
    return  true;

    }
};                                 

1005.最大和:维护一个数组maxsum保留在当前下标下,最大和是多少,往后不断更新。maxsum[i] = max(maxsum[i - 2] + A[i],maxsum[i - 1]);


class Solution {
public:
    int maxSum(vector<int>& A) {
        if(A.size() < 2)
        return A[0];
    if(A.size() == 2)
        return  A[0] > A[1] ? A[0] : A[1];
    int maxsum[100000] = {0};
    maxsum[0] = A[0],maxsum[1] = A[0] > A[1] ? A[0] : A[1];
    for(int i = 2;i < A.size();i++)
        maxsum[i] = max(maxsum[i - 2] + A[i],maxsum[i - 1]);
    return maxsum[A.size() - 1];  
    }
};           

1006.单词变换:dp[i][j]表示A串从第0个字符开始到第i个字符和B串从第0个字符开始到第j个字符,这两个字串的编辑距离。字符串的下标从1开始。若A[i]==B[j],dp[i + 1][j + 1] = dp[i][j];否则dp[i + 1][j + 1] = min(min(dp[i + 1][j] + 1,dp[i][j + 1] + 1),dp[i][j] + 1)。


class Solution {
public:
    int minDistance(string word1, string word2) {
       if(word1.size() == 0)
        return word2.size();
    if(word2.size() == 0)
        return word1.size();
    vector<vector<int>> dp(word1.size()+1,vector<int>(word2.size()+1));
    int i,j;
    for(i = 0;i < word1.size();i++)
        dp[i][0] = i;
    for(j = 0;j < word2.size();j++)
        dp[0][j] = j;
    for(i = 0;i < word1.size();i++)
        for(j = 0;j < word2.size();j++){
            char a = word1[i],b = word2[j];
            if(a == b)
                dp[i + 1][j + 1] = dp[i][j];
            else
                dp[i + 1][j + 1] = min(min(dp[i + 1][j] + 1,dp[i][j + 1] + 1),dp[i][j] + 1);
        }
    return dp[word1.size()][word2.size()];
       }
};                                 
开发区管委会想建立公共技术服务平台体系,在成果治理机制上该如何规划?.docx 开发区管委会想建立公共技术服务平台体系,在成果治理机制上该如何规划? 立即下载

相关推荐

省级技术交易市场目前的年均交易额规模和增长趋势如何?.docx

省级技术交易市场目前的年均交易额规模和增长趋势如何?

旷视2020图像算法工程师机考题(15道选择题)

Yancy的博客 1537

模型算力需求估算

(Billion Parameters,简称B)和训练/推理的计算任务复杂度,结合硬件计算能力(例如每秒浮点运算次数,FLOPS)来估算。以下是详细的方法和公式说明,以及实际的计算示例。算力需求的估算依赖于参数量、模型架构及硬件性能,结合训练/推理场景的特定要求来计算。通过上述公式和示例,我们可以定量分析不同任务的算力需求,并合理配置硬件资源以优化运行效率。结论:推理任务相对较轻,单台H100可以在30秒内完成此任务。推理算力需求一般远低于训练,因为只需要执行前向传播。,可以将训练时间缩短到约。

形上得其象,形下合于数;阴阳自济,玄理自明。 9004

第十周:[Leetcode]486. Predict the Winner

Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a

line02的专栏 497

Rust 语言入门

Rust 使 对您的编辑或工具或代码所在的位置没有特定要求,因此 如果您更喜欢使用集成开发环境 (IDE) 而不是 命令行,请随意使用您最喜欢的 IDE。对于简单的程序来说,只编译 是可以的,但作为你的项目 增长,您将需要管理所有选项并轻松共享您的 法典。接下来,我们将向您介绍 Cargo 工具,它将帮助您编写 真实世界的 Rust 程序。现在您已经安装了 Rust,是时候编写您的第一个 Rust 程序了。这不重要 到你的代码所在的 Rust,但对于本书中的练习和项目, 我们建议在你的主目录中创建一个。

JohnChen(Net) 1495

AnolisOS网卡驱动源码编译与安装实战指南

本文提供了一份详尽的AnolisOS网卡驱动源码编译与安装实战指南。针对系统自带通用驱动不兼容导致网络无法使用的问题,文章从环境准备、源码获取、编译安装到新旧驱动替换与持久化配置,一步步解析了如何通过源码编译安装官方驱动,解决硬件兼容性问题,并确保驱动在系统重启后自动生效。

weixin_28358083的博客 316

第十六周:[Sicily]1321. Robot

Description Karell Incorporated has designed a new exploration robot that has the ability to explore new terrains, this new robot can move in all kinds of terrain, it only needs more fuel to move in r

line02的专栏 462

告别ROS1思维:在ROS2 Humble上,用Python搞定MoveIt2机械臂控制的完整流程

本文详细介绍了在ROS2 Humble环境下使用Python控制MoveIt2机械臂的完整流程。从环境配置、架构变革到实战操作,涵盖URDF适配、Action接口编程及性能优化技巧,帮助开发者高效迁移ROS1项目至ROS2平台,实现工业级机械臂控制。

weixin_30352645的博客 453

第五周:[Leetcode]55. Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you

line02的专栏 423

STM32新手必看:3分钟搞定ST官网资料下载(附F0系列手册+外设库下载技巧)

本文为STM32开发新手提供高效获取ST官网技术资料的完整指南,重点介绍如何快速下载STM32F0系列数据手册和外设库。通过系统性的资源分类解析和实用下载技巧,帮助开发者快速定位所需文档,建立本地知识库,提升开发效率。

ujm5678901的博客 277

使用MATLAB中的Simulink工具来构建一个微电网系统的仿真平台

微电网是指由分布式电源(如太阳能、风能等)、储能装置、负载以及控制和保护装置组成的局部电力系统。它可以独立于主电网运行,也可以与主电网并联运行。本示例将以一个简单的微电网为例,展示如何利用Simulink进行微电网接入与孤岛运行策略的设计与仿真。分布式电源:模拟太阳能光伏板或风力发电机等分布式电源。储能装置:用于存储多余能量或补充不足能量。负载:模拟实际用电需求。双向变流器:实现直流与交流之间的转换,并支持并网和孤岛模式切换。控制器:负责管理微电网的运行模式,包括并网控制和孤岛控制。

xiaoheshang_123的博客 350

第八周:[Leetcode]5. Longest Palindromic Substring

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: “babad” Output: “bab” Note: “aba” is also a valid answer. Exampl

line02的专栏 377

微信8.0所有URL Scheme大全:隐藏入口与使用场景详解 内附195条微信URL Scheme

URL Scheme 类似于一个协议地址,它的作用和网页的https://差不多,只不过它不是打开网页,而是直接跳转到微信App内部的功能页面。→ 打开微信扫一扫→ 打开零钱通详情→ 打开微信面对面支付微信功能的“快捷指令”。整理下来,微信的 URL Scheme 基本覆盖了支付、联系人、扫一扫、小程序、运动设备等多个入口。对开发者来说,这些 Scheme 就像是隐藏的快捷通道,在某些场景(比如支付唤起、活动红包、客服入口)能大大简化流程。微信对外部调用限制非常严格。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 2290

第七周:[hihocoder]#1050 : 树中的最长路

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅仅可以拼凑成一棵二叉树!还可以拼凑成一棵多叉树——好吧,其实就是更为平常的树而已。 但是不管怎么说,小Ho喜爱的玩具又升级换代了,于是他更加爱不释手(其实说起来小球和木棍有什么好玩的是吧= =)。小Ho手中

line02的专栏 376

10.Labview局部变量、全局变量、引用、属性节点、调用节点用法理解及精讲

本文的结构还是首先教大家明确概念问题,然后深入理解概念并学会使用,最后在理论基础掌握的基础上,通过实例来强化大家的理解。本文依旧是**先理论后实践**的教学方式,欢迎留言或私聊提问。

关注我,更多技术问题欢迎私聊~ 1万+

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

第八周:[Leetcode]300. Longest Increasing Subsequence

Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], therefo

line02的专栏 361

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

第六周:[Leetcode]127. Word Ladder

Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that: Only one letter can be changed at a tim

line02的专栏 352

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

第五周:[Leetcode]121. Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), de

line02的专栏 343

第十三周:[Sicily]1423. 魔王bug的2色定理

Description 背景: 传说中魔王bug被杀时留下了一股神秘的力量,但是同时也留下了一个具难的题目,如果你能解答这个 具难的题目,你就能获得bug魔王留下的神秘力量…… 题目描述: 魔王bug的难题来自于它自创的2色定理,魔王bug坚信:天地万物,有阴必有阳,有正必有负,有黑必有白, 有邪恶的魔王必有正义的天使 >_< ….. 魔王bug留下了一幅N个点M个边的图,图中有些点已

line02的专栏 338

第十九周:课后习题8.8

解: 对于任意一个3SAT实例: 若其中某个子句中包含了同一个文字多次,则可以将这些相同的文字合并为一次; 若某个变量同时包含了true和false,则该变量可以去掉。 因此,在每个子句中添加一些没用的辅助变量,这样就可以将每个子句中包含的文字数目扩充到四个。 即将3SAT实例转化成了一个EXACT 4SAT问题。 这就通过将3SAT归约到

line02的专栏 337

第一周:[LeetCode]1. Two Sum

[LeetCode]1. Two Sum

line02的专栏 325

第四周:[LeetCode]332. Reconstruct Itinerary

Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the

line02的专栏 310

第十八周:[Leetcode]98. Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. The r

line02的专栏 302

第十四周:[LeetCode]10. Regular Expression Matching

Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string

line02的专栏 300
上一篇: 第十六周:[Sicily]1321. Robot
下一篇: 第十八周:[Leetcode]74. Search a 2D Matrix
line02
博客等级 码龄15年 3粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值