UVA 10474 --- Where is the Marble? 二分查找
来源:互联网 发布:python正则匹配 编辑:程序博客网 时间:2024/06/07 09:12
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int s[100010];int b_find(int l,int r,int sr){ while(l <= r) { int mid = (l + r) >> 1; if(s[mid] == sr) return mid; else if(sr < s[mid]) r = mid - 1; else if(sr > s[mid]) l = mid + 1; } return -1;}int main(){ int n,m,sr,c = 0,fh; while(scanf("%d%d",&n,&m),n || m) { for(int i = 0;i < n;i++) scanf("%d",&s[i]); sort(s,s + n); printf("CASE# %d:\n",++c); for(int i = 0;i < m;i++) { scanf("%d",&sr); if((fh = b_find(0,n - 1,sr)) != -1) { while(fh > 0 && s[fh] == s[fh - 1]) fh--; printf("%d found at %d\n",sr,fh + 1); } else printf("%d not found\n",sr); } } return 0;}
0 0
- UVA 10474 --- Where is the Marble? 二分查找
- UVA.10474 Where is the Marble ( 排序 二分查找 )
- UVa 10474 Where is the Marble? (二分查找&equal_range()的使用)
- uva 10474 - Where is the Marble?(排序,二分搜索)
- uva 10474 Where is the Marble?(二分STL)
- 排序/查找 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?
- UVa 10474 - Where is the Marble?
- UVa 10474 - Where is the Marble
- UVa 10474 - Where is the Marble?
- UVA 10474 Where is the Marble?
- 怎样用UltraISO制作U盘系统安装盘
- gdb调试
- Java随笔
- 结构型模式之Proxy模式
- Java字符串的substring真的会引起内存泄露么?
- UVA 10474 --- Where is the Marble? 二分查找
- 学习opencv第三章答案
- linux-sed命令
- JDK1.6的ConcurrentHashMap
- 删除超过50行的数据库数据
- git和svn协作
- linux-awk命令详解
- 释放动态创建的二维数组时出现内存访问异常
- LeetCode Valid Parentheses