大理石在哪?(Where is the Marble?,UVa 10474)
2016-07-19 11:06
375 查看
参考:ACM紫书 第五章 P108 【排序与检索】
下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改。
#include <cstdio> #include <algorithm> using namespace std; const int maxn = 10000; int main(void) { int n,q,numarr[maxn],i,x,p,Case=0; while(scanf("%d%d",&n,&q)==2 && n) { printf("CASE# %d:\n",++Case); for(i=0; i<n; i++) { scanf("%d",&numarr[i]); } sort(numarr,numarr+n); while(q--) { scanf("%d",&x); printf("%d--%p\n",*numarr,numarr); printf("%d--%p\n",*lower_bound(numarr,numarr+n,x),lower_bound(numarr,numarr+n,x)); p=lower_bound(numarr,numarr+n,x)- numarr; printf("p = %d\n",p); if(numarr[p]==x)printf("%d found at %d\n",x,p+1); else printf("%d not found\n",x); } } return 0; }
相关文章推荐
- 在 Linux 上使用 VirtualBox 的命令行管理界面
- dTree组件的学习
- Disruptor 详解
- C语言putenv()函数:改变或增加环境变量
- Java 的JSON、XML转换方法——目录索引
- org.apache.log4j.Logger 详解
- java 抽象类和接口区别
- 安卓软键盘隐藏
- 高效调用lua函数
- 设置Grails中的domain的字段默认是否允许为空
- Kafka0.8.2.1删除topic逻辑
- json性能测试
- 在 Ubuntu Mate 16.04 上通过 PPA 升级 Mate 1.14
- Java NIO
- 白菜之重写toString()、equals()方法的注意事项
- putenv()
- Java 应用一般架构
- idea常用的快捷键
- 10张图带你深入理解Docker容器和镜像
- Android中的Activitys, Threads和内存泄露