回复: 2
跳转到指定楼层
上一主题 下一主题
收起左侧

开车AI家的几道OA题

全局:

2017(7-9月) 码农类General 硕士 全职@DAi - 网上海投 - 在线笔试  | | Other | 其他

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
我把自己连猜带蒙写的Solution都贴出来了,不知道下周会不会HR联系我
class Point {
public:
    int x, y;
    int value;
    int id;
    Point(int x, int y, int value=0, int id=0) {
        this->x=x;
        this->y=y;
        this->value=value;
        this->id=id;
    }
};
void test() {
    vector<vector<Point*>> points;
    points.push_back({});
    points[0].push_back(new Point(0, 0, 1));
    points[0].push_back(new Point(0, 1, 1));
    points[0].push_back(new Point(0, 2));
    points[0].push_back(new Point(0, 3));
    points[0].push_back(new Point(0, 4));
    points.push_back({});
    points[1].push_back(new Point(1, 0, 1));
    points[1].push_back(new Point(1, 1, 1));
    points[1].push_back(new Point(1, 2));
    points[1].push_back(new Point(1, 3));
    points[1].push_back(new Point(1, 4));
    points.push_back({});
    points[2].push_back(new Point(2, 0));
    points[2].push_back(new Point(2, 1));
    points[2].push_back(new Point(2, 2, 1));
    points[2].push_back(new Point(2, 3));
    points[2].push_back(new Point(2, 4));
    points.push_back({});
    points[3].push_back(new Point(3, 0));
    points[3].push_back(new Point(3, 1));
    points[3].push_back(new Point(3, 2));
    points[3].push_back(new Point(3, 3, 1));
    points[3].push_back(new Point(3, 4, 1));
    points.push_back({});
    points[4].push_back(new Point(4, 0));
    points[4].push_back(new Point(4, 1));
    points[4].push_back(new Point(4, 2));
    points[4].push_back(new Point(4, 3, 1));
    points[4].push_back(new Point(4, 4, 1));
    /*
     1 1 0 0 0
     1 1 0 0 0
     0 0 1 0 0
     0 0 0 1 1
     0 0 0 1 1
     */
    vector<vector<Point*>> result = pixelClustering(points, 1, 3);
}

vector<vector<Point*>> pixelClustering(vector<vector<Point*>>& points, int dist, int counts) {
    if (points.empty() || points.size()==0 || points[0].size()==0) {
        return points;
    }
    vector<vector<Point*>> result=points;
    int newid=1;
    for (int i=0; i<result.size(); i++) {
        for (int j=0; j<result[0].size(); j++) {
            if (result[i][j]->value==1) {
                int counter=1;
                dfsHelper(points, i, j, dist, counter);
                if (counter<counts) {
                    cleaner(points, i, j, dist);
                }
                else {
                    remarker(points, i, j, dist, newid);
                    newid++;
                }
            }
        }
    }
    return result;
}

private:
void remarker(vector<vector<Point*>>& points, int x, int y, int dist, int newid) {
    points[x][y]->value=2;
    points[x][y]-&g
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
ed_map<string, vector<string>> graph, unordered_map<string, bool>& available, vector<string>& result) {
    unordered_map<string, int> state;
    for (auto it = graph.begin(); it != graph.end(); ++it) {
        state[it->first]=0;
    }
    for (auto it = graph.begin(); it != graph.end(); ++it) {
        if (available[it->first]==true) {
            visit(graph, it->first, result, state);
        }
    }
    return;
}

void visit(unordered_map<string, vector<string>>& image,
           string it,
           vector<string>& list,
           unordered_map<string, int>& state) {
    if (state[it]==3) {
        return;
    }
    if (state[it]==2) {
        return;
    }
    state[it]=2;
    for (auto neib:image[it]) {
        visit(image, neib, list, state);
    }
    state[it]=3;
    list.push_back(it);
}

void buildGraph(vector<vector<string>>& image, unordered_map<string, vector<string>>& graph) {
    for (int i=0; i<image.size(); i++) {
        graph[image[i][0]].push_back(image[i][1]);
    }
}

bool isCyclicHelper(string v, unordered_map<string, vector<string>>& graph, unordered_map<string, bool>& visited, unordered_map<string, bool>& recStack) {
    if (visited[v]==false) {
        visited[v]=true;
        recStack[v]=true;
        for (auto it=graph[v].begin(); it!=graph[v].end(); ++it) {
            if (!visited[*it] && isCyclicHelper(*it, graph, visited, recStack)) {
                return true;
            }
            else if (recStack[*it]==true) {
                return true;
            }
        }
    }
    recStack[v]=false;
    return false;
}

评分

参与人数 1大米 +3 收起 理由
Lyu + 3 感谢分享!

查看全部评分


上一篇:爷儿谱跪经
下一篇:twitter OA test 7
🔗
snmnmin 2017-8-27 08:27:50 | 只看该作者
本楼:
全局:
这么长。。。
回复

使用道具 举报

🔗
小师妹 2017-10-7 10:50:36 | 只看该作者
全局:
请问楼主拿到店面了吗,求店面面经
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表