全部评论
测试用例 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)
现在把自己改来改去的代码放出来吧,反正与网易无缘了,测试用例也全靠回忆,要是有大佬来看出错误欢迎指正。
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; }
#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;
代码比较丑,但这是我过的唯一一道了T_T
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; }
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; }
#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; }
相关推荐
昨天 22:03
武汉理工大学 Java 菜菜菜小白菜菜菜:我在字节实习了四个月,有转正的压力所以周末大部分也在公司自学,也是因为一些原因转正拖的很久,这个点还没答辩,过段时间才回去答辩。整个不确定性的焦虑贯穿了我的秋招三个月,我也曾经犹豫过是不是应该放弃转正走秋招更快,最后因为沉没成本一直舍不得放弃,前前后后七个月真的挺累的,尤其是没有来字节实习的同学已经校招拿到意向时更加焦虑。这段时间也跟mentor聊了很多次,他告诉我未来工作上或者生活上,比这些更头疼的事情会更多,关键还是要调整好自己的心态。转正没有通过从过程上来看其实跟你自身没太大的关系,拖了三个月不出结果显然是ld的问题,并且今年美团最近的开奖大家似乎都不是很乐观,所以不去也罢。我在字节实习的时候,6月份有一个赶上春招末期的25届同事刚面进来,也拿到了小sp的薪水。不要对这件事有太大的压力,时代的问题罢了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 评论 收藏
分享

查看3道真题和解析