UVa 10474 Where is the Marble
2015-02-19 13:47
281 查看
题意:给出一列数,先排序,再查找
学习了sort函数,lower_bound函数
sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)
lower_bound:查找大于或者等于x的第一个位置。
View Code
学习了sort函数,lower_bound函数
sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)
lower_bound:查找大于或者等于x的第一个位置。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=10005; int a[maxn]; int main() { int n,p,q,x,ncase=1; while(scanf("%d %d",&n,&q)!=EOF&&n) { for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); printf("CASE# %d:\n",ncase); while(q--) { scanf("%d",&x); p=lower_bound(a,a+n,x)-a; if(a[p]==x) printf("%d found at %d\n",x,p+1); else printf("%d not found\n",x); } ncase++; } return 0; }
View Code
相关文章推荐
- UVa 10474 Where is the Marble? (二分查找&equal_range()的使用)
- UVA 10474 Where is the Marble?
- uva 10474 Where is the Marble? 计数排序
- UVA 10474 - Where is the Marble?
- uva 10474 Where is the Marble?
- UVA 10474 Where is the Marble?
- UVa 10474 - Where is the Marble
- Uva 10474 Where is the Marble?
- uva 10474 Where is the Marble?
- uva-10474 - Where is the Marble?
- UVa10474 Where is the Marble?
- UVA10474 - Where is the Marble?
- UVa 10474 - Where is the Marble?
- UVa - 10474 - Where is the Marble?
- uva 10474 - Where is the Marble?
- UVA 10474 - Where is the Marble?
- UVa 10474 Where is the Marble?
- UVa 10474 - Where is the Marble?
- uva 10474 Where is the Marble? 计数排序
- UVa 10474 - Where is the Marble?