全部评论
#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; }
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; }
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; }
代码比较丑,但这是我过的唯一一道了T_T
#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;
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; }
现在把自己改来改去的代码放出来吧,反正与网易无缘了,测试用例也全靠回忆,要是有大佬来看出错误欢迎指正。
测试用例 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)
相关推荐
点赞 评论 收藏
分享
![](https://static.nowcoder.com/head/4photo.jpg)
点赞 评论 收藏
分享