First ,i think the issue is that we have int a[998]
a[0]..a[997] store the number from 1..1000,missed 2 and no duplication
The best way from Computer science is below:
###pay attention that a^a=0
int result=0;
for(int i=0;i<997;i++)
{
result = result ^ a[i];
}
for(int i=1;i<1001;i++)
{
result = result ^ i;
}
###then result is just missing number1 ^ missing number2.
since they are different,there must be one digit is not the same of the two
number.
int index=1;
if!(result & 1<阅读全帖
follow一下我的面经。 http://www.mitbbs.com/article_t/JobHunting/32517841.html
整理了我的几个解答的算法,分享一下。欢迎批评指正。
多谢!
1. 写一个程序,找出 5^1234566789893943的从底位开始的1000位数字。
我用的递归+数组大数乘法。
// Caclulate (m^n)%(10^k). Keep the k integer numbers in an array.
// Note: the integer numbers are in reversed in the array
// Assume: m>0, n>0, k>0
// Need to check validity outside of this function.
// call calculate(5, 1234566789893943, 1000) to get result.
// Time complexity: O((log n) * k * k)
// Space complexity: O((log n) * k)
ve... 阅读全帖
follow一下我的面经。 http://www.mitbbs.com/article_t/JobHunting/32517841.html
整理了我的几个解答的算法,分享一下。欢迎批评指正。
多谢!
1. 写一个程序,找出 5^1234566789893943的从底位开始的1000位数字。
我用的递归+数组大数乘法。
// Caclulate (m^n)%(10^k). Keep the k integer numbers in an array.
// Note: the integer numbers are in reversed in the array
// Assume: m>0, n>0, k>0
// Need to check validity outside of this function.
// call calculate(5, 1234566789893943, 1000) to get result.
// Time complexity: O((log n) * k * k)
// Space complexity: O((log n) * k)
ve... 阅读全帖
原题在这里。 http://www.mitbbs.com/article_t/JobHunting/32517841.html 但是觉得不太对
搞这些题觉得很没思路。
// Caclulate (m^n)%(10^k). Keep the k integer numbers in an array.
// Note: the integer numbers are in reversed in the array
// Assume: m>0, n>0, k>0
// Need to check validity outside of this function.
// call calculate(5, 1234566789893943, 1000) to get result.
// Time complexity: O((log n) * k * k)
// Space complexity: O((log n) * k)
vector calculate(unsigned long m, unsigned long n, int k) {
if(... 阅读全帖
我觉得第三题应该这么做:
首先扔2次不够,因为扔2次的话,组合和概率是这样的:
T T:1/16
T F: 3/16
F T: 3/16
F F: 9/16
没有一种组合可以得到8/16 = 1/2
所以必须扔3次,扔3次的组合和概率是这样的:
T T T: 1/64
T T F: 3/64
T F T: 3/64
T F F: 9/64
F T T: 3/64
F T F: 9/64
F F T: 9/64
F F F: 27/64
这里面有好几个组合可以得到32/64 = 1/2,最简单的是F T T + F F F. 最后我的解法
是:
result1 = rand();
result2 = rand();
result3 = rand();
if (!result1&&result2&&result3 || !result1&&!result2&&!result3)
return true;
else
return false;
扔4次也可以,但是没必要。
哪位大侠指教一下?
这个不是精度的问题,是.net怎么储存double
A mathematical or comparison operation that uses a floating-point number
might not yield the same result if a decimal number is used, because the
binary floating-point number might not equal the decimal number. A previous
example illustrated this by displaying the result of multiplying .1 by 10
and adding .1 times.
When accuracy in numeric operations with fractional values is important, you
can use the Decimal rather than the Double type. When accuracy in numeric
operat... 阅读全帖
I have a large SAS data set (result) with 1599000 observations. It's
actually 1000 replicates of a single file with 1599 observations. Now I
want to output every 1599 observations to a separate data set (result1 -
result1000):
data result1-result1000;
set result;
do i=1 to 1000;
if (i-1)*1599<_N_=
end;
run;
How should I specify the data set that the observations should be written
to? I tried result||'i' but it did not work~
Thank you so much!!!!