标签:
#include<iostream> #include<vector> using namespace std; void findOddMin(vector<vector<int>> &a, int m, int n, vector<int> &r) { int len = r.size(); vector<int> tmp; for (int i = 0; i < m; ++i){ int b = 0, e = n - 1; if (i % 2 == 0){ if (i / 2>0) b = r[i / 2 - 1]; if (i / 2 < len) e = r[i / 2]; int k = b; for (int j = b + 1; j <= e; ++j) if (a[i][j] < a[i][k]) k = j; tmp.push_back(k); } else tmp.push_back(r[i / 2]); } r = tmp; } void findMin(vector<vector<int>> &a, int m, int n, vector<int> &r) { if (m == 1){ int k = 0; for (int i = 1; i < n; ++i) if (a[0][i] < a[0][k]) k = i; r.push_back(k); return; } vector<vector<int>> b; for (int i = 0; i < m; ++i) if (i % 2 == 1) b.push_back(a[i]); findMin(b, m / 2, n, r); findOddMin(a, m, n, r); } int main() { //vector<vector<int>> a = { { 10, 13, 23 }, { 17, 16, 23 }, { 45, 32, 23 } }; vector<vector<int>> a = { { 37, 23, 22, 32 }, { 21, 6, 5, 10 }, { 53, 34, 30, 31 }, { 32, 13, 9, 6 }, { 43, 21, 15, 8 } }; vector<int> r; findMin(a, 5,4, r); for (auto i : r) cout << i << ‘ ‘; cout << endl; }
标签:
原文地址:http://www.cnblogs.com/jokoz/p/4693042.html