题目大意
小A教室的墙上挂满了气球,五颜六色,小朋友们非常喜欢。
刚一下课,小朋友们就打算去抢这些气球。每个气球在墙上都有一定的高度,只有当小朋友跳起来时,手能够到的高度大于等于气球的高度,小朋友才能摘到这个气球。为了公平起见,老师让跳的低的小朋友先摘,跳的高的小朋友后摘。小朋友都很贪心,每个小朋友在摘气球的时候都会把自己能摘的气球都摘掉。
很巧的是,小朋友们跳起来手能够着的高度都不一样,这样就不会有跳起来后高度相同的小朋友之间发生争执了。
题目分析
很简单的排序+双指针,不解释了。
也可以排序+二分,多个$\log$,反正不卡你。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std;
inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; }
const int maxn=100005; int n,m,b[maxn],Ans[maxn]; struct Student { int h,id; bool operator < (const Student& b) const { return h<b.h; } } a[maxn];
int main() { n=Get_Int(); m=Get_Int(); for(int i=1; i<=n; i++)a[i].h=Get_Int(),a[i].id=i; for(int i=1; i<=m; i++)b[i]=Get_Int(); sort(a+1,a+n+1); sort(b+1,b+m+1); a[0].h=-1; int pos=0,lastpos=0; for(int i=1; i<=n; i++) { while(pos<m&&a[i].h>=b[pos+1])pos++; Ans[a[i].id]=pos-lastpos; lastpos=pos; } for(int i=1; i<=n; i++)printf("%d\n",Ans[i]); return 0; }
|