两个二分函数lower_bound和upper_bound函数
lower_bound函数查找的是大于等于key的位置
upper_bound函数查找的是大于key的位置
和sort函数有点类似的!~
具体用法反正不怎么会;
会用就可以了,看个例子吧:
CF上的一道题:
http://codeforces.com/contest/953/problem/A
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const ll MAX=2e9+1; 5 ll ans[10005]; 6 int cnt=0; 7 void init() 8 { 9 for(int i=0;i<=30;i++) 10 { 11 for(int j=0;j<=30;j++) 12 { 13 ll t=pow(2,i)*pow(3,j); 14 if(t<MAX) 15 { 16 ans[++cnt]=t; 17 } 18 } 19 } 20 } 21 int main() 22 { 23 init(); 24 sort(ans+1,ans+1+cnt); 25 int l,r; 26 while(scanf("%d%d",&l,&r)!=EOF) 27 { 28 int L=lower_bound(ans+1,ans+1+cnt,l)-(ans+1);///查找大于等于l的位置 29 int R=upper_bound(ans+1,ans+1+cnt,r)-(ans+1);///查找大于r的位置 30 printf("%d\n",R-L); 31 } 32 return 0; 33 }
大概会用就可以了,知道返回的值就OK!~!
了解就好了。