由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - CheckForZero
相关主题
用STL map的时候怎么自己定义大小比较的关系再问个关于中止程序的问题
Interview questionhow to reverse a HUGE list?
算法问题关于 VC++ vitual, reload 和 derive的一个问题...
Do the two statements cost the same amount of time?请教Office Automation Add-in的高手
两个矩阵的算法题[合集] one simple question
tail call strange behavior on cl.exe[合集] 和大家再讨论一道面试算法题(MS) (转载)
C++ optimization question[合集] funny code I saw in work
用C++的写的numerical or optimization solver library问问题C
相关话题的讨论汇总
话题: int话题: does话题: element
进入Programming版参与讨论
1 (共1页)
M**8
发帖数: 25
1
HI, I saw this on internet. Not exactly sure what it wants. Why not use
mulplication instead of ADD, SUB suggested?
int CheckForZero (int a[], int n)
{
int i;
for (i = 0; i < n; i++) {
if (a[i] == 0) {
return (TRUE);
}
}
return (FALSE);
}
This code works - but it does a check for every element in 'a' - i.e.
it does 'n' compares and bails early if it finds even one zero element.
Our array 'a' generally does not have a zero. Optimize this code to
do only one compare. Feel free
f*****Q
发帖数: 1912
2
乘法太慢,从电路的角度很好解释。
M**8
发帖数: 25
3
I doubt AND would work. Can you give more details?
(0xFF00 & 0x00FF) == 0
t****t
发帖数: 6806
4
oops, my fault. never mind.

【在 M**8 的大作中提到】
: I doubt AND would work. Can you give more details?
: (0xFF00 & 0x00FF) == 0

l***8
发帖数: 149
5
mulplication won't work either because size of machine word is limited (e.g.
32-bit "int"). try multiply 65536 and 65536 and you get back "0".
1 (共1页)
进入Programming版参与讨论
相关主题
问问题C两个矩阵的算法题
cin.clear() 怎么用tail call strange behavior on cl.exe
*********VBA Macro 打开 Excel 问题.***********C++ optimization question
python高手请进,RFC文件转换成kindle格式的代码用C++的写的numerical or optimization solver library
用STL map的时候怎么自己定义大小比较的关系再问个关于中止程序的问题
Interview questionhow to reverse a HUGE list?
算法问题关于 VC++ vitual, reload 和 derive的一个问题...
Do the two statements cost the same amount of time?请教Office Automation Add-in的高手
相关话题的讨论汇总
话题: int话题: does话题: element