首页 > 网易互娱AI研究工程师岗位第一题讨论
头像
Adherer要加油呀~
发布于 2020-04-11 21:34
+ 关注

网易互娱AI研究工程师岗位第一题讨论

// 第一题这个堆排序错在哪了?
#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
struct maze {
    int value;
    double dis_with_center;
    maze(int v, double dis) {
        value = v;
        dis_with_center = dis;
    }
    friend bool operator < (maze a, maze b) {
        return a.dis_with_center > b.dis_with_center;
    }
};
priority_queue<maze> que;
int L;
int num[510][510];

int main () {
    int T;
    int M;
    int x, y;
    cin >> T;
    while (T--) {
        cin >> M >> L;
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < M; j++) {
                cin >> num[i][j];
            }
        }
        cin >> x >> y;
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < M; j++) {
                if (num[i][j] > 0) {
                    que.push(maze(num[i][j], sqrt(pow(x - i, 2) + pow(y - j, 2))));
                }
            }
        }
//        priority_queue<maze> tmp = que;
//        while (!tmp.empty()) {
//            cout << tmp.top().dis_with_center << " " << tmp.top().value << endl;
//            tmp.pop();
//        }
        while (!que.empty()) {
            if (L >= que.top().dis_with_center) {
                L += que.top().value;
                que.pop();
            } else {
                break;
            }
        }
        cout << L << endl;
    }
    return 0;
}


第一题应该就是一个堆排序,重载一下<运算符就好了,但是始终都是通过0%,样例都过了,也测试了好几组数据,始终找不到错在哪,求大神指点一下。。

全部评论

(0) 回帖
加载中...
话题 回帖

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

热门推荐