2 条题解
-
2
#include <bits/stdc++.h> using namespace std; int vec[1000007]; int qq[1000007]; int k; //映射 map<int,int > m; map<int,int >::iterator it; //vector<int >::iterator p; int *p; int main() { int n, q; //cin >> n>>q; scanf("%d %d", &n, &q); //int temp; for (int i = 0; i < n; i++) { scanf("%d", &vec[i]); //vec.push_back(temp); } //sort(vec.begin(),vec.end()); sort(vec, vec + n); //int temp; for (int i = 1; i <= q; i++) { scanf("%d", &qq[i]); m[qq[i]] = -1; } ///memcpy(qqq,qq,sizeof(qq)); int *pp=vec; //for (int i = 1; i <= q; i++) { for(it = m.begin();it!=m.end();it++){ p = upper_bound(pp, vec + n, it->first); if (p == vec + n) { //putchar('0'); //puts("0"); //cout<<0<<endl; //printf("0\n"); m[it->first] = 0; } else { //printf("%d\n", *p); m[it->first] = *p; //qqqq[i] = *p; pp = p; //cout<<*p<<endl; } } //4 3 //4 1 4 9 //5 10 4 /* for(it = m.begin();it!=m.end();it++){ cout<<it->first<<" "<<it->second<<endl; } */ for (int i = 1; i <= q; i++) { printf("%d\n", m[qq[i]]); } return 0; }
-
1
/1、4149对4判断 2、对5判断 3、对10判断/ #include<bits/stdc++.h> using namespace std; int a[1000001]; int b[1000001]; int c[1000001]; int cnt=0; int main() { int n, q; cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= q; i++) { cin >> b[i]; } sort(a+1,a+n+1); for(int i=1;i<=q;i++){ for(int j=1;j<=n;j++){ if(a[j]>b[i]){ cnt++; c[cnt]=a[j]; } if(j==n&&a[j]<b[i]){ cnt++; c[cnt]=0; } } } for(int i=1;i<=cnt;i++){ cout<<c[i]<<endl; } return 0; }
- 1
信息
- ID
- 170
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 15
- 已通过
- 0
- 上传者