网易笔试

求第一题那个10*10数组
代码或者题目都行
没过想回顾一下
#网易#
全部评论
#include <iostream> #include <vector> #include <cmath> using namespace std; const int int_max = 0x3f3f3f3f; double dis(int x1, int y1, int x2, int y2) {     int x = abs(x1 - x2);     int y = abs(y1 - y2);     return sqrt(pow(x, 2) + pow(y, 2)); } vector<vector<double>> diss(vector<vector<int>> vvi, int size, int x, int y) {     vector<vector<double>> res(size, vector<double>(size, int_max));     for (int i = 0; i < size; ++i)     {         for (int j = 0; j < size; ++j)         {             if (vvi[i][j] != 0)             {                 res[i][j] = dis(x, y, i, j);             }         }     }     return res; }
点赞 回复 分享
发布于 2020-04-11 21:47
bool getL(vector<vector<double>> &vvi, int len, int &rx, int &ry) {     for (int i = 0; i < vvi.size(); ++i)     {         for (int j = 0; j < vvi.size(); ++j)         {             if (vvi[i][j] <= len)             {                 vvi[i][j] = int_max;                 rx = i;                 ry = j;                 return true;             }         }     }     return false; }
点赞 回复 分享
发布于 2020-04-11 21:47
int main(int argc, char const *argv[]) {     int T;     cin >> T;     for (int i = 0; i < T; ++i)     {         int M, L;         cin >> M >> L;         vector<vector<int>> place(M, vector<int>(M, 0));         for (int j = 0; j < M; ++j)         {             for (int k = 0; k < M; ++k)             {                 cin >> place[j][k];             }         }         int x, y;         cin >> x >> y;         vector<vector<double>> dist = diss(place, M, x, y);         int rx, ry;         while (true)         {             bool ans = getL(dist, L, rx, ry);             if (!ans)             {                 break;             }             else             {                 L += place[rx][ry];             }         }         cout << L << endl;     }     system("pause");     return 0; }
点赞 回复 分享
发布于 2020-04-11 21:47
代码比较丑,但这是我过的唯一一道了T_T
点赞 回复 分享
发布于 2020-04-11 21:48
#include<iostream> #include<vector> #include<math.h> #include<algorithm> #include<map> int b[500][500]; double e[500]; using namespace std; int main() { int T; cin >> T; int i; int j; for (i = 0; i < T; i++) { int M; int L; cin >> M; cin >> L; for (j = 0; j < M; j++) { for (int m = 0; m < M; m++) { cin >> b[j][m]; } } int x; int y; cin >> x; cin >> y; i = 0; map<double, int> mp;
点赞 回复 分享
发布于 2020-04-11 22:12
for (j = 0; j < M; j++) { for (int m = 0; m < M; m++) { if (b[j][m] != 0) { cout << "b[j][m]" << b[j][m] << " " << "j" << j << " " << m << endl; double q = (x - j)*(x - j) + (y - m)*(y - m); cout << "q" << q << endl; e[i] = q; if (mp[e[i]] != 0)mp[e[i]] += b[j][m]; else mp[q] = b[j][m]; i++; } } } for (j = 0; j < i; j++)cout << e[j]<<endl; sort(e, e + i); for (j = 0; j < i; j++)cout << e[j] <<" "<<mp[e[j]]<<endl; j = 0; while(mp[e[j]]<=L&&j<i){ if (e[j + 1] == e[j]) j++; L = L + mp[e[j]]; j++; cout << "L" << L<<"i"<<i<<" "<<j<<endl; } cout << L << endl; } return 0; }
点赞 回复 分享
发布于 2020-04-11 22:12
现在把自己改来改去的代码放出来吧,反正与网易无缘了,测试用例也全靠回忆,要是有大佬来看出错误欢迎指正。
点赞 回复 分享
发布于 2020-04-11 22:13
测试用例         2                              // 2 组         10 3                           // 10 x 10 大小,刀长 3         0 0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0 0         0 0 0 0 2 0 0 0 0 0         0 0 0 0 0 0 0 0 0 0         0 0 0 0 1 0 2 0 0 0         0 0 0 0 0 0 0 0 0 2         0 0 0 1 0 0 0 0 0 1         0 0 0 1 0 0 2 0 2 0         8 8                            // 起始位置 (8,8)         10 2                           // 10 x 10 大小,刀长 2         0 0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0 0         0 0 0 0 0 0 0 0 0 0         0 0 2 0 0 1 0 0 0 0         0 0 0 1 2 0 2 0 0 0         0 0 0 0 2 1 2 0 2 0         0 0 2 0 0 0 0 0 2 0         0 0 0 0 0 0 0 2 0 0         0 0 0 1 0 0 0 0 0 0         2 5                             // 起始位置 (2,5)
点赞 回复 分享
发布于 2020-04-11 22:21

相关推荐

头像
02-15 16:23
中南大学 Java
野猪不是猪🐗:签了美团真是不一样! 亲戚们都知道我签了美团,过年都围着我问送一单多少钱,还让弟弟妹妹们引以为戒,笑我爸我妈养了个🐢孩子,说从小就知道我这个人以后肯定没出息,我被骂的都快上天了
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客企业服务