Login
Register
Problem list
Online status
harkerhand
:
2025-04-25 17:30:52
好吧正经答案,O(m+n) #include
using namespace std; #define int long long signed main() { int t; cin >> t; while (t--) { int m, n, ta; cin >> m >> n >> ta; vector
> a(m, vector
(n)); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; int row = 0, col = n - 1; bool found = false; while (row < m && col >= 0) { int val = a[row][col]; if (val == ta) { found = true; break; } else if (val > ta) col--; else row++; } cout << boolalpha << found << endl; } }
harkerhand
:
2025-04-25 17:27:03
有点暴力了,但是能过,嘻嘻 #include
using namespace std; #define int long long signed main() { int t; cin >> t; while (t--) { int m, n, ta; cin >> m >> n >> ta; vector
a(m * n); for (int i = 0; i < m * n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); cout << boolalpha << (find(a.begin(), a.end(), ta) != a.end()) << endl; } }
Ranking
:
2023-06-01 16:47:32
这道题时间限制还挺松的。。。
Post Your Comment