结束2分钟后调好的,也不知道能不能完全通过 #include <iostream> #include<vector> #include <algorithm> using namespace std; int n; long long x[50]; long long y[50]; int test() { long long min_x = 1000000000, min_y = 1000000000, max_x = 0, max_y = 0; for (int i = 0; i < n; i++) { if (x[i] < min_x) min_x = x[i]; if (y[i] < min_y) min_y = y[i]; if (x[i] >max_x) max_x = x[i]; if (y[i] > max_y) max_y = y[i]; } vector<long long> min1(n,1000000000); int num = 0; for (int _x = min_x; _x <=max_x; _x++) { for (int _y = min_y; _y <=max_y; _y++) { vector<long long> dist(n); for (int k = 0; k < n; k++) { dist[k] = abs(_x - x[k]) + abs(_y - y[k]); } std::sort(dist.begin(), dist.end(), less<int>()); for (int k = 1; k < n; k++) { dist[k] = dist[k] + dist[k-1]; } for (int k = 0; k < n; k++) { min1[k] = min(min1[k],dist[k]); } } } for (int i = 0; i < n; i++) cout << min1[i]; return 1; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> x[i]; for (int i = 0; i < n; i++) cin >> y[i]; test(); return 0; }
点赞 5

相关推荐

11-01 20:03
已编辑
门头沟学院 算法工程师
Amazarashi66:这种也是幸存者偏差了,拿不到这个价的才是大多数
点赞 评论 收藏
分享
牛客969571862号:昨天捞我今天面这个,岗位一模一样,感觉就是面着玩
点赞 评论 收藏
分享
牛客网
牛客企业服务