大理石在哪儿 (排序和查找) UVA
来源:互联网 发布:mac install ipython 编辑:程序博客网 时间:2024/04/30 14:11
题意:有n个数,现在给你一个x,问是不是存在x;
思路:用lower_bound返回第一个大于等于x的地址,如果相等,则存在;否则,不存在。
/*** Welcome To See My Code ***//***If I get TLE , it is good.If I get AC,it's NICE !***/#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <vector>#include <cmath>#include <queue>#include <string>#include <map>using namespace std;typedef long long ll;const int INF=2147483647;const int MAXN=1e5+10;const ll mod=1e9+7;using namespace std;typedef long long ll;int a[MAXN];int main(void){ int n; int q; int kase=1; while((scanf("%d%d",&n,&q))==2) { if(n==0 & q==0) break; printf("CASE# %d:\n",kase); kase++; for(int i=1; i<=n; i++) scanf("%d",&a[i]); sort(a+1,a+1+n); for(int i=1; i<=q; i++) { int x; scanf("%d",&x); int pos=lower_bound(a+1,a+1+n,x)-a; if(a[pos]==x) printf("%d found at %d\n",x,pos); else printf("%d not found\n",x); } }}
1.这题的思路在后面的比赛里我马上就碰到了。非常重要。
阅读全文
0 0
- 大理石在哪儿 (排序和查找) UVA
- UVa 10474 大理石在哪儿
- 大理石在哪儿(UVa 10474)(排序与检索)
- 例题:大理石在哪儿(UVa 10474)
- 大理石在哪儿
- 紫书章五 大理石在哪 UVA 10474(stl排序查找)
- UVa 10474 Where is the Marble?(大理石在哪儿)
- uva 10474 Where is the Marble?(大理石在哪儿)
- 大理石在哪儿(Where is the marble?,UVa 10474)
- 10474 - 大理石在哪儿Where is the Marble?(排序+检索)
- STL初步:大理石在哪儿?
- C++之大理石在哪儿?
- 算法入门经典:大理石在哪儿
- uva10474大理石在哪儿where is the marble?
- 大理石在哪儿?(Stl lower_bound用法)
- 例题5-1 大理石在哪儿 UVa10474
- 大理石在哪儿 where is the Marble? lower_bound()
- 大理石在哪儿 where is the Marble?
- div#sidebar{}与#sidebar div{}的区别
- lowbit
- mysql恢复之delete 忘加where条件误删除恢复(binglog格式必须是ROW)
- 现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中心的半径为实数Ri(0<Ri<15)的圆被湿润,这有充足的喷水装置i(1<i<600)个,并
- Day2
- 大理石在哪儿 (排序和查找) UVA
- centOS6.8升级gcc
- 《深入理解Java虚拟机》读书笔记(2)---第3章 垃圾收集器与内存分配策略(一)
- Goole C++ 单元测试框架(一)
- Java GC与内存分配策略
- 廖雪峰python教程实战 Day 4
- 使用wait和notify模拟queue
- Play framework主要概念MVC应用模型
- 51Nod-斜率最大