[Interview] 2022.08——Horizon Autonomous Driving Regulation and Control Position One and Two Faces

one side

2022.8.19

  • Ask project

  • Do a math problem: Given a polynomial, turn it into a quadratic form to express
    f ( x 1 , x 2 , x 3 ) = ( x 1 − 1 ) 2 + ( x 2 − 2 ) 2 + ( x 3 − 3 ) 2 + ( x 1 − x 2 ) 2 + ( x 2 − x 3 ) 2 x 1 , x 2 , x 3 ∈ R f\left(x_1, x_2, x_3\right)=\left(x_1-1\right )^2+\left(x_2-2\right)^2+\left(x_3-3\right)^2+\left(x_1-x_2\right)^2+\left(x_2-x_3\right)^ 2\\ x_1, x_2, x_3 \in \mathbf{R}f(x1,x2,x3)=(x11)2+(x22)2+(x33)2+(x1x2)2+(x2x3)2x1,x2,x3R

    • Write this function in quadratic form as a matrix and vector.
    • What are the necessary and sufficient conditions for this function to take the minimum value?
  • Coding link: Given the coordinates A, B and point C of the two endpoints of a line segment, find the coordinates of the projection point from point C to line segment AB.

  • intentionally

  • career planning

Two sides - terminated (hand-teared but not torn out)

2022.8.26

Insert image description here

25 minutes, if it is not written out, the process will be terminated directly .

  • How to use adjacency matrix

    #include<iostream>
    #include<vector>
    #include<string>
    #include <queue>
    #include <algorithm>
    
    using namespace std;
    
    vector<vector<int>>adjacency_matrix(vector<vector<int>>graph){
          
          
        int n = graph.size();
        vector<vector<int>>mat(n,vector<int>(n,0));
        for(int i=0;i<n;i++){
          
          
            mat[graph[i][0]][graph[i][1]]=graph[i][2];
        }
        return mat;
    }
    int sum=0;
    vector<int>res;
    void backtracking(vector<vector<int>>mat,int start,int end){
          
          
        if(start==end){
          
          
            res.push_back(sum);
            return;
        }
        if(start==0)return;
        for(int i=0;i<mat[start].size();i++){
          
          
            if(mat[start][i]==0)continue;
            sum+=mat[start][i];
            backtracking(mat,i,end);
            sum-=mat[start][i];
        }
    }
    
    int main(){
          
          
        vector<vector<int>>graph ={
          
          {
          
          1,2,3},{
          
          1,3,2},{
          
          1,4,1},{
          
          2,5,2},{
          
          3,6,1},{
          
          4,6,4},{
          
          4,5,3},{
          
          6,5,3}};
        vector<vector<int>>adj = adjacency_matrix(graph);
        //打印邻接矩阵
    //    for(int i=0;i<adj.size();i++){
          
          
    //        for(int j=0;j<adj[i].size();j++){
          
          
    //            cout<<adj[i][j]<<' ';
    //        }
    //        cout<<endl;
    //    }
        backtracking(adj,1,5);
        sort(res.begin(),res.end());
        for(int i=0;i<res.size();i++){
          
          
            cout<<res[i]<<' ';
        }
       return 0;
    }
    
    
  • How to use adjacency lists

    #include<iostream>
    #include<vector>
    #include<string>
    #include <queue>
    #include <algorithm>
    
    using namespace std;
    
    
    vector<vector<pair<int,int>>>adjacency_list(vector<vector<int>>graph){
          
          
        int n = graph.size();
        vector<vector<pair<int,int>>>mat(n);
        for(int i=0;i<n;i++){
          
          
            mat[graph[i][0]].push_back({
          
          graph[i][1],graph[i][2]});
        }
        return mat;
    }
    int sum=0;
    vector<int>res;
    void backtracking(vector<vector<pair<int,int>>> mat,int start,int end){
          
          
        if(start==end){
          
          
            res.push_back(sum);
            return;
        }
        for(int i=0;i<mat[start].size();i++){
          
          
            sum+=mat[start][i].second;
            backtracking(mat,mat[start][i].first,end);
            sum-=mat[start][i].second;
        }
    }
    
    int main(){
          
          
        vector<vector<int>>graph ={
          
          {
          
          1,2,3},{
          
          1,3,2},{
          
          1,4,1},{
          
          2,5,2},{
          
          3,6,1},{
          
          4,6,4},{
          
          4,5,3},{
          
          6,5,3}};
        vector<vector<pair<int,int>>>adj = adjacency_list(graph);
        backtracking(adj,1,5);
        sort(res.begin(),res.end());
        for(int i=0;i<res.size();i++){
          
          
            cout<<res[i]<<' ';
        }
       return 0;
    }
    
    

Guess you like

Origin blog.csdn.net/qq_40145095/article/details/126696266