11 条题解
-
0鸟大师 (slz钟鼎皓) LV 8 @ 2024-6-1 19:14:58
#include<iostream> using namespace std; int a[1000005],n,m,b; bool find(int x){ int l=1,r=n; while(l<=r){ int mid=(l+r)>>1; if(a[mid]==x)return 1; else if(a[mid]>x)r=mid-1; else l=mid+1; } return 0; } int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; cin>>m; while(m--){ cin>>b; if(find(b))cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; } //钟鼎皓 💩ㄟ( ▔, ▔ )ㄏ💩
-
02024-4-22 21:27:34@
#include<bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; const int N=1e6+10; int n; int a[N]; int b[N]; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } int m; cin>>m; for(int i=1;i<=m;i++){ cin>>b[i]; } for(int i=1;i<=m;i++){ int l=1,r=n; int key=0; while(l<=r){ int mid=l+r>>1; if(a[mid]==b[i]){ key=1; break; } else{ if(a[mid]<b[i]) l=mid+1; else{ r=mid-1; } } } if(key==0) cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 0; }
-
02024-4-2 17:25:19@
using namespace std; const int INF=0x3f3f3f3f; const int N=1e5+10; int n; int a[100000005]; int b[100000005]; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } int m; cin>>m; for(int i=1;i<=m;i++){ cin>>b[i]; } for(int i=1;i<=m;i++){ int l=1,r=n; int ans=0; while(l<=r){ int mid=(l+r)/2; if(a[mid]==b[i]){ ans=1; break; } else{ if(a[mid]<b[i]) l=mid+1; else{ r=mid-1; } } } if(ans==0) cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 0; }
-
02024-3-6 19:09:58@
#include<iostream> using namespace std; int a[1000005],n,m,b; bool find(int x){ int l=1,r=n; while(l<=r){ int mid=(l+r)>>1; if(a[mid]==x)return 1; else if(a[mid]>x)r=mid-1; else l=mid+1; } return 0; } int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; cin>>m; while(m--){ cin>>b; if(find(b))cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
-
02023-5-29 16:42:31@
#include <queue> #include <math.h> #include <stack> #include <vector> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include<cstring> #include <algorithm> using namespace std; #define LL long long const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; using namespace std; int n , m , a [ N ] ; bool find ( int x ) { int l = 1 , r = n ; while ( l <= r ) { int mid = l + r >> 1 ; if ( a [ mid ] == x ) return 1 ; else if ( a [ mid ] > x ) r = mid - 1 ; else l = mid + 1 ; } return false ; } int main() { cin >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> a [ i ] ; } sort (a + 1 ,a + n + 1) ; cin >> m ; while ( m -- ) { int x ; scanf ("%d" , & x ) ; cout << (find( x ) ? "YES":"NO") << endl ; } return 0; }
-
02023-5-14 19:31:22@
#include <iostream> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int m; cin >> m; int b[m]; for (int i = 0; i < m; i++) { cin >> b[i]; } for (int i = 0; i < m; i++) { int l = 0, r = n - 1; bool flag = false; while (l <= r) { int mid = (l + r) / 2; if (a[mid] == b[i]) { flag = true; break; } else if (a[mid] > b[i]) r = mid - 1; else l = mid + 1; } if (flag) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
-
02023-5-2 15:53:35@
#include<iostream> using namespace std; int a[1000005],n,m,b; bool bs(int x) { int l = 1,r = n; while(l <= r) { int mid =(l + r) >> 1; if(a[mid] == x) return 1; else if(a[mid] > x)r = mid - 1; else l = mid + 1; } return 0; } int main() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; cin >> m; while(m--) { cin >> b; if(bs(b)) cout << "YES" << endl; else cout << "NO" <<endl; } return 0; }
-
-12023-5-14 19:23:16@
#include<bits/stdc++.h> #define int long long using namespace std; int n,a[1000005],m,x; void ss(){ int l=1,r=n; while(l<=r){ int mid=(l+r)/2; if(x<a[mid])r=mid-1; if(x>a[mid])l=mid+1; if(x==a[mid]){cout<<"YES"<<endl;return;} } cout<<"NO"<<endl; return; } signed main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; cin>>m; sort(a+1,a+1+n); for(int i=1;i<=m;i++){cin>>x;ss();} }
-
-12023-5-1 9:55:04@
using namespace std; int a[1000000]; int main(){ int n; cin >> n; for (int i=0; i<n; i++){ cin >> a[i]; } int m; cin >> m; bool flag=false; while(m--){ bool flag=false; int b; cin >> b; int l=0, r=n-1; while(l<=r){ int mid = (l+r)/2; if (a[mid]==b){ cout << "YES" << endl; flag = true; break; } else if (a[mid]<b){ l=mid+1; } else{ r=mid-1; } } if(flag==false){ cout << "NO" << endl; } } return 0; }//简单易懂
-
-22023-5-1 9:36:42@
#include<bits/stdc++.h> using namespace std; const int N=1e6+10; long long a[N]; long long n,x,m; bool check(int x) { bool flag=0; int l=1,r=n; while(l<=r) { int mid=(l+r)/2; if(a[mid]==x) { flag=1; break; } if(a[mid]<x) l=mid+1; else r=mid-1; } return flag; } int main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; cin>>m; for(int i=1;i<=m;i++) { cin>>x; if(check(x)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
-
-22023-4-23 13:46:01@
#include<iostream> using namespace std; int a[1000009]; int main(){ int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } int m;cin>>m; while(m--){ int l=0,r=n-1; int b; cin>>b; int flag=0; while(l<=r){ int mid=(l+r)/2; if(b==a[mid]){ cout<<"YES"<<endl; flag=1; break; }else if(b<a[mid]){ r=mid-1; //好好想想这个关系为啥是-1 }else if(b>a[mid]){ l=mid+1; //好好想想这个关系为啥是+1 } } if(flag==0){ cout<<"NO"<<endl; } } //超时的话就用scanf printf(#include<cstdio>) 这比cin cout 快呀 }
- 1
信息
- ID
- 1278
- 时间
- 3000ms
- 内存
- 512MiB
- 难度
- 7
- 标签
- 递交数
- 855
- 已通过
- 171
- 上传者