20分求助!玄关

题目总版

wangxx2012 @ 2024-11-14 12:45:59

传送门

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[100010],b[100010],cnt;
signed main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++) cin>>b[i];
    sort(a+1,a+n+1);
    sort(b+1,b+m+1);
    for(int i=1;i<=n;i++){
        int l=1,r=m,mid=(r+l)/2;
        while(l<=r){
            if(b[mid]==a[i]){
                cout<<a[i]<<" ";
                break;
            }
            else if(b[mid]<a[i]){
                l=mid+1;
                mid=(r+l)/2;
            } 
            else{
                r=mid-1;
                mid=(r+l)/2;
            }
        }
    }
    return 0;
}

by cengzh @ 2024-11-14 12:52:17

这题用桶会不会更好?


by wangxx2012 @ 2024-11-14 12:55:08

@cengzh用桶会存不下吧


by cengzh @ 2024-11-14 12:57:59

@wangxx2012 感觉勉勉强强可以


by wangxx2012 @ 2024-11-14 13:00:15

@cengzh求大佬指导代码


by cengzh @ 2024-11-14 13:04:37

您看错题了

按在科技创新奖获奖名单中的先后次序输出

所以不需要对a排序,但是改了也只有80分

再看看


by wangxx2012 @ 2024-11-14 13:10:33

@cengzh本地已经AC了,已关


by cengzh @ 2024-11-14 13:11:05

qwq


|