算法面试题(格灵深瞳)

目录

  • 1 智慧星球的武器(100分)
  • 2 匹配先验框(这个只得了80分)

最近做了格灵深瞳算法题目,这个公司是研究计算机视觉的,算法自然绕不开人工智能的那些图像处理算法。我虽然是学视觉SLAM,但是对图像处理的一些算法不甚了解,做起来有点吃力。
这里分享两个比较简单的算法笔试题吧。有想准备这家公司的可以参考一下

1 智慧星球的武器(100分)

算法面试题(格灵深瞳)_第1张图片

#include 
#include 
#include 
#include 
#include 


using namespace std;

class Light
{
public:
    Light(int sLength)
    {
        sLength_ = sLength;
    }

public:
    int sLength_;
};

class Jiejie
{
public:
    Jiejie(int &Ltype, int &Lmodel)
    {
        Ltype_ = Ltype;
        Lmodel_ = Lmodel;
    }
public:
    int Ltype_;
    int Lmodel_;
};

int main()
{
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int k, m, p;
    vector<pair<int,int>> groups;
    Light Jig(1);
    cin >> k;
    for (int i = 0; i < k; ++i)
    {
        cin >> m >> p;
        groups.push_back(make_pair(m,p));
    }
    
    for (vector<pair<int, int>>::iterator iter = groups.begin(); iter != groups.end(); iter++)
    {
        switch (iter->first)
        {
        case 1:
            Jig.sLength_ += iter->second;
            break;
        case 2:
            Jig.sLength_ *= iter->second;
            break;
        case 3:
            Jig.sLength_ = ceil(Jig.sLength_ * 1.0 / iter->second);
            break;
        }
    }

    cout << Jig.sLength_ << endl;

    return 0;
}

2 匹配先验框(这个只得了80分)

算法面试题(格灵深瞳)_第2张图片

#include 
#include 
#include 
#include 
#include 
using namespace std;


struct prior
{
    int w;
    int h;
    int s;
    int t;
};

struct target
{
    int X;
    int Y;
    int W;
    int H;
};


vector<prior> getPriors(int w, int h, int s, int t, int P, int Q)
{
    prior pri;
    vector<prior> priors;
    int ss = 0;
    while (ss + w <= P)
    {
        int tt = 0;
        while (tt + h <= Q)
        {
            pri.s = ss;
            pri.t = tt;
            pri.w = ss + w;
            pri.h = tt + h;

            priors.push_back(pri);
            tt += t;
        }
        ss += s;
    }

    return priors;
}

int retNum(vector<prior> priors, vector<target> vecs, int k)
{
    int num = 0;
    for (size_t i = 0; i < priors.size(); i++)
    {
        for (int j = 0; j < k; j++)
        {
            int dis1 = min(priors.at(i).w, vecs.at(j).W) - max(priors.at(i).s, vecs.at(j).X);
            int dis2 = min(priors.at(i).h, vecs.at(j).H) - max(priors.at(i).t, vecs.at(j).Y);

            if (dis1 > 0 && dis2 > 0)
            {
                num++;
                break;
            }

        }
    }

    return num;
}

int main()
{
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */

    int w, h, s, t, k, P, Q;
    cin >> w >> h >> s >> t >> k >> P >> Q;

    vector<target> vecs;
    target tag;
    int X, Y, W, H;
    for (int i = 0; i < k; i++)
    {
        cin >> X >> Y >> W >> H;
        tag.X = X;
        tag.Y = Y;
        tag.W = W + X;
        tag.H = H + Y;

        vecs.push_back(tag);
    }

    vector<prior> priors = getPriors(w, h, s, t, P, Q);


    int num = retNum(priors, vecs, k);

    cout << num << endl;

    return 0;
}

你可能感兴趣的:(周边工具学习笔记,算法)