标签:c++ iostream namespace struct typedef
2 3 1 1 2 1 1 2 5 2 9 5 20 11 9 1 1 1 20
2 44
代码如下
#include <iostream> using namespace std; int abs(int m) { if(m >= 0) return m; else return -m; } int main() { int x[100], y[100]; int n, m; cin >> n; while(n --) { cin >> m; int tep = 0; while(m >= 1) { cin >> x[tep] >> y[tep]; tep ++; m --; } int minSum = 0; for(int k = 0; k < tep; k ++) minSum += abs(x[k] - 1) + abs(y[k] - 1); for(int j = 2; j <= 100; j ++) { for(int i = 2; i <= 100; i ++) { int thisSum = 0; for(int k = 0; k < tep; k ++) { thisSum += abs(x[k] - i) + abs(y[k] - j); } if(thisSum < minSum) minSum = thisSum; } } cout << minSum << endl; } return 0; }
标签:c++ iostream namespace struct typedef
原文地址:http://blog.csdn.net/u012970287/article/details/42612649