ural 1064 Binary Search
2011-02-10 22:37
232 查看
简单的模拟, 不过要注意这组数据......
Sample Input
9999 14
Sample Output
1
10000 10000
Sample Input
9999 14
Sample Output
1
10000 10000
]#include<iostream> #define MAXN 10000 using namespace std; int T[MAXN+2]; int N,ni,nL,tot; int want[MAXN/2][2]; void BinarySearch(int x) { int p,q,i,L; p=0; /* Left border of the search */ q=N-1; /* Right border of the search */ L=0; /* Comparison counter */ while(p<=q) { i=(p+q)/2; ++L; if(i==x) { if(L==nL) T =1; return; } if(L>nL) return; if(x<i) q=i-1; else p=i+1; } return; } int main() { int i,temp; scanf("%d%d",&ni,&nL); for(N=ni;N<=10000;N++) BinarySearch(ni); for(i=0;i<=10001;i++) { if(T[i]) { temp=i; for(++i;i<=10001;i++) if(!T[i]) break; tot++; want[tot][0]=temp; want[tot][1]=i-1; } } printf("%d/n",tot); for(i=1;i<=tot;i++) printf("%d %d/n",want[i][0],want[i][1]); return 0; }
相关文章推荐
- 1064.Complete Binary Search Tree
- 1064. Complete Binary Search Tree
- 1064. Complete Binary Search Tree
- ural 1998
- URAL1132_Square Root
- 九度-1064-反序数
- URAL——1005 stone pile
- Ural 1982 Electrification Plan (prim最小生成树)
- URAL 1167. Bicolored Horses (DP)
- URAL 1244. Gentlemen
- 约瑟夫问题 URAL 1098
- poj 1064 Cable master
- URAL 1362. Classmates 2
- URAL Goat in the Garden(圆与矩形求交集面积)
- poj 1064 Cable master(二分)
- URAL 1648 Yachts
- Ural 1167 Bicolored Horses (DP)
- ural 1146. Maximum Sum(dp)
- URAL 1297 Palindrome (最长回文子串)
- ural 1020. Rope(几何)