吉比特2018春招编程题题解

吉比特2018春招技术类笔试试卷编程题题解,先给出AC代码,CSDN上的题解明天给出吧

GitHub上的代码:https://github.com/FlushHip/AlgorithmnCode/blob/master/吉比特2018春招技术类笔试试卷编程题

#include <bits/stdc++.h>

using namespace std;

int main()
{
    for (int n1, n2; cin >> n1 >> n2; ) {
        int ans = 0;
        unsigned int n_1 = n1, n_2 = n2;
        for (int i = 0; i < 32; i++) {
            ans += (n_1 & 1) ^ (n_2 & 1);
            n_1 >>= 1;
            n_2 >>= 1;
        }
        cout << ans << endl;
    }
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define gcd __gcd

struct Point {
    int x, y, z;
    Point() {}
    Point(int x, int y, int z) : x(x), y(y), z(z) {}

    bool operator<(const Point &other) const {
        if (x != other.x)
            return x < other.x;
        if (y != other.y)
            return y < other.y;
        if (z != other.z)
            return z < other.z;
    }
};

typedef pair<pair<int, int>, int> Node;

int main()
{
    for (int n; cin >> n; ) {
        vector<Point> points;
        for (int i = 0, x, y, z; i < n; i++)
            cin >> x >> y >> z, points.push_back(Point(x, y, z));
        sort(points.begin(), points.end());

        int ans = 0;
        for (int i = 0; i < n; i++) {
            map<Node, int> mp;
            for (int j = i + 1; j < n; j++) {
                int vx = points[j].x - points[i].x;
                int vy = points[j].y - points[i].y;
                int vz = points[j].z - points[i].z;
                int g = gcd(gcd(vx, vy), vz);
                mp[make_pair(make_pair(vx / g, vy / g), vz / g)]++;
            }
            int sum = 0;
            for (auto it = mp.begin(); it != mp.end(); ++it)
                sum = max(sum, it->second);
            ans = max(sum, ans);
        }
        cout << ans + 1 << endl;
    }
    return 0;
}
#春招##吉比特#
全部评论
楼主好厉害!可以分享下学习算法经验吗!好头晕😭😭
点赞 回复
分享
发布于 2018-03-30 22:00
我都没做完
点赞 回复
分享
发布于 2018-03-30 22:18
博乐游戏
校招火热招聘中
官网直投
能讲下思路吗,第二题
点赞 回复
分享
发布于 2018-03-31 09:36
阳哥
点赞 回复
分享
发布于 2018-03-31 09:40
666,大佬大佬
点赞 回复
分享
发布于 2018-03-31 09:51
原来你是19届的。。看你好早准备春招?
点赞 回复
分享
发布于 2018-03-31 10:14

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务