#include#include #include #include using namespace std; const int N = 1e3 + 10; #define int long long int n, m; vector > p; bool check (int tar) { vector abl(m); bool pair = 0; for (int i = 0; i < n; i ++) { int c = 0; for(int j = 0; j < m; ++j){ if(p[i][j] >= tar){ abl[j] = true; c++; } } if (c > 1) pair = 1; } if (!pair && m > 1) return 0; bool ans = 1; for (bool t : abl) ans = ans && t; return ans; } signed main() { int _; cin >> _; while (_ --) { cin >> n >> m; p.assign(n, vector (m)); for (int i = 0; i< n; i ++) { for (int j = 0; j < m; j ++) { cin >> p[i][j]; } } int l = 1, r = 1e9; while(l < r) { int mid = (l + r + 1)/ 2; if (check(mid)) l = mid; else r = mid - 1; } cout << l << endl; } return 0; }
首先如果能够至少达到x,那么一定至少能够达到x - 1,否则如果不能达到x,那么也不能够达到x + 1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)