Redian新闻
>
Sero现在还能转么?转了还能保留号码到别的carrier么?
avatar
Sero现在还能转么?转了还能保留号码到别的carrier么?# PDA - 掌中宝
b*n
1
"Programming Pearls" has a binary search program that searches the first
occurrence of a certain value. I think it is a little confusing so I wrote
it in another way:
/* Function that returns the first occurrence of x.
* arr is input sorted array, arr_size is the number of elements in arr,
* x is the value that we are looking for.
* Returns index of the element, or -1 if element is not found. */
int first_occurrence(int* arr, int arr_size, int x)
{
int l = 0;
int u = arr_size - 1;
while (l + 1 < u) {
int m = l + (u - l) / 2;
if (arr[m] < x)
l = m + 1; // line 8: both "l = m" and "l = m + 1" will work here?
else
u = m;
}
if (arr[l] == x)
return l;

if (arr[u] == x)
return u;
return -1;
}
My question is on line 8 (see the comments on that line). I tested a few
cases and it seems that both "l = m" or "l = m + 1" will work. Can anybody
confirm that? Thanks.
avatar
s*g
2
☆─────────────────────────────────────☆
tnsunbirdy1 (yaya) 于 (Fri Jun 4 15:07:56 2010, 美东) 提到:
刚才在网上看到有个人因为体检医生没有给他做TB 测试,只是在体检表上写上了以前
什么时候做的,结果是阳性,然后做的X-光的结果,因此引来了REF。请版上那么多过
了的过来人给讲讲,这是个普通个例,还是这种情况就是得从新作TB测试。
☆─────────────────────────────────────☆
laoda555 (俺老大) 于 (Fri Jun 4 15:09:29 2010, 美东) 提到:
你的证明若超过了两年, 就老老实实地去做。
☆─────────────────────────────────────☆
tnsunbirdy1 (yaya) 于 (Fri Jun 4 15:22:00 2010, 美东) 提到:
我的没事,我做了TB 测试。
我认识的一个人,在出国前作了TB test, 可是体检医生说不用重新做,每再做一次测
试,情况会
avatar
H*7
3
否则,哼哼,子弹不长眼
avatar
n*e
4
有个合同到期的sero,不想继续用sprint了
avatar
r*n
5
I think it's right.
loop invariant: x[l]<=t<=x[u] and x[l] is left most one.
at end of loop, u = l+1, and you check x[l] and x[u].
I can't find anything you miss.

first
wrote
arr,

【在 b*****n 的大作中提到】
: "Programming Pearls" has a binary search program that searches the first
: occurrence of a certain value. I think it is a little confusing so I wrote
: it in another way:
: /* Function that returns the first occurrence of x.
: * arr is input sorted array, arr_size is the number of elements in arr,
: * x is the value that we are looking for.
: * Returns index of the element, or -1 if element is not found. */
: int first_occurrence(int* arr, int arr_size, int x)
: {
: int l = 0;

avatar
d*8
6
这个好笑么?
学术版请不要发不学术的主题
avatar
b*n
7
Thanks. Your confirmation makes me feel better.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。