#include <bits/stdc++.h> using namespace std; #define CHAR_BIT 8 inline int myabs(int v){ // int v; // we want to find the absolute value of v unsigned int r; // the result goes here int const mask = v >> sizeof(int) * CHAR_BIT - 1; r = (v ^ mask) - mask; return r; } unsigned long long int centra[5]; int t[5][100000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N,K; cin >> N >> K; // array<array<int, 3 >, 5 > t; // vector<vector<int > > t; // t.resize(K); // int t[3][5]; for(int i=0; i<K; i++){ for(int j=0; j<N; j++){ int v; cin >> v; t[i][j] = v; // t[i].push_back( v ); } } for(int i=0; i<K; i++){ for(int a=i+1; a<K; a++){ unsigned long long int sum = 0; for(int j=0; j<N; j++){ sum += myabs(t[i][j] - t[a][j]); } centra[i] = max(sum, centra[i]); centra[a] = max(sum, centra[a]); #ifdef DEBUG cout << i << " + " << a << ", Sum = " << sum << endl; #endif } } #ifdef DEBUG for(int i = 0; i < K; i++){ cout << i << " -> " << centra[i] << endl; } #endif #ifdef DEBUG cout << "idx: " << (min_element(centra, centra+K) - centra) << endl; #endif // for(const auto &x : t[(min_element(centra, centra+K) - centra)]){ // cout << x << " "; // } // cout << endl; // // test return // cout << *min_element(centra, centra+K) << endl;; // proper return int min_elem = (min_element(centra, centra+K) - centra); for(int i=0;i<N;i++){ cout << t[min_elem][i] << " "; } cout << endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #include <bits/stdc++.h> using namespace std; #define CHAR_BIT 8 inline int myabs(int v){ // int v; // we want to find the absolute value of v unsigned int r; // the result goes here int const mask = v >> sizeof(int) * CHAR_BIT - 1; r = (v ^ mask) - mask; return r; } unsigned long long int centra[5]; int t[5][100000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N,K; cin >> N >> K; // array<array<int, 3 >, 5 > t; // vector<vector<int > > t; // t.resize(K); // int t[3][5]; for(int i=0; i<K; i++){ for(int j=0; j<N; j++){ int v; cin >> v; t[i][j] = v; // t[i].push_back( v ); } } for(int i=0; i<K; i++){ for(int a=i+1; a<K; a++){ unsigned long long int sum = 0; for(int j=0; j<N; j++){ sum += myabs(t[i][j] - t[a][j]); } centra[i] = max(sum, centra[i]); centra[a] = max(sum, centra[a]); #ifdef DEBUG cout << i << " + " << a << ", Sum = " << sum << endl; #endif } } #ifdef DEBUG for(int i = 0; i < K; i++){ cout << i << " -> " << centra[i] << endl; } #endif #ifdef DEBUG cout << "idx: " << (min_element(centra, centra+K) - centra) << endl; #endif // for(const auto &x : t[(min_element(centra, centra+K) - centra)]){ // cout << x << " "; // } // cout << endl; // // test return // cout << *min_element(centra, centra+K) << endl;; // proper return int min_elem = (min_element(centra, centra+K) - centra); for(int i=0;i<N;i++){ cout << t[min_elem][i] << " "; } cout << endl; return 0; } |