in my area, go to city and request a copy of the original builder's blue print. it should show the prop line. requirements maybe diff in your city but the survey purpose is mainly to decide where the border line is and make sure your fence doesn't go up on neighbor's lot
north jersey. i did that, about $900. if only survey with only "paper", it is cheaper. u have to ask them to put iron stake in the ground, more expensive. even though i did that, the neighbour still has problem with me.
How about this one? Any suggestions or corrections will be highly appreciated. #include #include int divide (int x, int y) { long long dividend, divisor, sign_dividend, sign_divisor; long long low, middle, high; int quotient; /* check whether divisor is 0 */ if (y == 0) { printf("Dvided by 0 error! \n"); assert(0); }
/* unsign both dividend and divisor and mark the signess */ if (x < 0) { dividend = -x; sign_dividend = -1; } else { dividend = x; sign_dividend = 1; } if (y < 0) { divisor = -y; sign_divisor = -1; } else { divisor = y; sign_divisor = 1; } /* case dividend is equal to divisor */ if(dividend == divisor) { if((sign_dividend + sign_divisor) == 0) return -1; else return 1; } /* case divisor is 1 */ if(divisor == 1) { quotient = (int)dividend; if((sign_dividend + sign_divisor) == 0) return -quotient; else return quotient; } /* binary search the quotient */ low = 0; high = dividend; while(1) { middle = (low+high)>>1; if (middle*divisor > dividend) high = middle; else low = middle; if((low==high) || (low==(high-1))) break; } if(high*divisor == dividend) quotient = (int)high; else quotient = (int)low; if((sign_dividend + sign_divisor) == 0) return (-quotient); else return quotient; }
I guess the right shift is allowed. But I still think there is a possibility to have overflow even though long is used. Actually, I don't think multiplication is needed and I think sub/add is enough to avoid potential problem and also good for performance, i.e., faster than multiplication when you think the deeper implementation. Have not written my own version by bin-search though.
【在 z*d 的大作中提到】 : Thanks. You're right. : For the divide by 2, is it OK to use right shift by 1 bit? : For potential overflow, we can use long to fix it. Right?
z*d
27 楼
With long long type, it should be ok for the overflow issue, I think. As for the performance, I'm also curious whether there is binary search solution with only add/sub operations, instead of multiplication.
【在 r*****e 的大作中提到】 : I guess the right shift is allowed. : But I still think there is a possibility to have overflow : even though long is used. Actually, I don't think multiplication : is needed and I think sub/add is enough to avoid potential problem : and also good for performance, i.e., faster than multiplication : when you think the deeper implementation. : Have not written my own version by bin-search though.
y*m
28 楼
看来还是蛮多细节疏忽了... function int calc(int x,y){ if(y==0) return null; else if (x==0) return 0;
if (x>0) c = 1; else c = -1;
if (y>0) d = 1; else d = -1;
int n = x*c; int m = y*d; if(nreturn 0;
int k=0; while(n>=m){ k++; n=n-m; } return k*c*d; }
【在 l*****a 的大作中提到】 : the most important : what will happen if y==0