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<阅读全帖
我觉得第三题应该这么做:
首先扔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... 阅读全帖
An issue that must have an elegant and simply solution.
I am trying to use transpose on a dataset, however how do
I specify all the variables?
if the are named col1, col1, etc, it is ok to use: var col1-col99
however what if they have random names, I have been trying to export
the data to excel, copy the header(variable name), then paste it back
to sas like
proc transpose data=original out=out;
var test1 result2 test2 result2........;
run;
is there a way to do this without specifying all