1 solutions
-
0
模板题,套就完事了 和P1117一模一样
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m,num; int a[1005]; int find(int l,int r,int num) { int mid; while(l<r) { mid=l+r>>1; if(a[mid]>=num) r=mid; else l=mid+1; } if(num==a[l]) return l+1; else return -1; } int main() { cin>>n>>m; for(int i=0;i<n;++i) { cin>>a[i]; } sort(a,a+n); while(m--) { cin>>num; cout<<find(0,n-1,num)<<" "; } return 0; }
Information
- ID
- 271
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 143
- Accepted
- 76
- Uploaded By