Login
Register
Problem list
Online status
算法大王肉肉肠
:
2026-05-27 11:37:25
#include
#include
using namespace std; int main(){ int t; cin>>t; while(t--){ int m,n,K; cin>>m>>n>>K; vector
> matrix(m,vector
(n,0)); for(int i =0;i
>matrix[i][j]; } } int i = 0,j = n-1; bool shysta=false; while(i < m&& j >= 0){ if(K==matrix[i][j]) { shysta=true; break; } if(K
matrix[i][j]){ i++; } } cout<<(shysta?"true":"false")<
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