由买买提看人间百态

topics

全部话题 - 话题: result1
(共0页)
o**2
发帖数: 168
1
来自主题: Programming版 - FMP 进驻 Programming 版
会用OO编程的应该就会用FM编程,因为FM可以被当作utilities来用,门坎很低。你只
需要在你需要的地方加一点点FM就可以了。
比如说你有一段程序如下,其中的两个worker objects做的都是耗时的工作。因为是顺
序执行的,程序要花25秒才能到300行。
100 Object result1 = worker1.do10seconds();
200 Object result2 = worker2.do15seconds();
300 makeUseOf(result1, result2);
不管你的整个程序或系统有多大,你可以只在这三行程序上使用FM编程。
// 必要的设置
50 Messenger messenger = new Messenger();
60 messenger.registerReceiver(worker1, "worker1", "do10seconds");
70 messenger.registerReceiver(worker2, "worker2", "do15seconds");
100 IDeferredReturn result1 ... 阅读全帖
l*****a
发帖数: 14598
2
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<阅读全帖
f*******t
发帖数: 7549
3
平衡括号的题可以用贪心法做吧
#include
#include
#include
#include
#define INVALIDCHAR -1
using namespace std;
char *balance(char *str)
{
int len = strlen(str);
if(len < 1)
return NULL;

char *buff = (char*)calloc(len + 1, 1);
stack left;
for(int i = 0; i < len; i++) {
if(str[i] == '(')
left.push(i);
else if(str[i] == ')') {
if(left.empty()) {
buff[i] = INVALIDCHAR;
co... 阅读全帖
s*******s
发帖数: 1031
4
来自主题: JobHunting版 - 我的几个面试算法解答。
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... 阅读全帖
s*******s
发帖数: 1031
5
来自主题: JobHunting版 - 我的几个面试算法解答。
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... 阅读全帖
y***n
发帖数: 1594
6
原题在这里。 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(... 阅读全帖
b*******l
发帖数: 590
7
来自主题: JobHunting版 - Groupon面筋。。。。
我觉得第三题应该这么做:
首先扔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次也可以,但是没必要。
哪位大侠指教一下?
B*****g
发帖数: 34098
8
来自主题: Database版 - T-SQL 问题
包子。回这篇文章被老板看见了
CREATE PROCEDURE sp_RandomLettersGenerator
( @randomLetters varchar(100) OUT)
AS
Declare @letters1 varchar(100)
Declare @letters2 varchar(100)
set @letters1='qwertyuiopasdfghjklzxcvbnm'
set @letters2='qazwsxedcrfvtgbyhnujmikolp'
set @randomLetters = substring(@letters1, cast(round(rand()*10,0) as int), 3)
+ substring(@letters2, cast(round(rand()*10,0) as int),3)
GO
declare @result1 varchar(100)
exec sp_randomLettersGenerator @result1 out
select @result1

from
P********l
发帖数: 452
9
来自主题: Programming版 - 春运网站架构之争 MapReduce vs MPI
买一张票的复杂度度是1的话,买两张票的复杂度还是1.
买一张票的时间符合泊松分布,买两张票可能还是泊松分布.(我的排队论学得最烂了)
过程大概是:
p1 = buy ticket 1; //买票1,异步
p2 = buy ticket 2; //买票2,异步
wait(p1, p2).
then(function(result1, result2){ //两张票状态全部返回以后.
if(result1.success && result2.success){ //全买到了
check out.
}else{ //至少一张没买到
if(result1.success){
p3 = (return ticket 1); //退票,异步
}
if(result2.success){
p4 = (return ticket 2); //退票,异步
}
}
}).
always(function(){
//exception.
});
wait(p3).then()
wait(p4).then()
c*********n
发帖数: 1057
10
来自主题: JobHunting版 - 一道小题
用recursive容易很多啊
void comb(int l,int r, char *result,int size){
//printf("%d, %d, %s\n",l,r,result);
if(l==0 && r==0){
printf("%s\n",result);
return;
}
if(l==r){
strcat(result,"(");
comb(l-1,r,result,size);
}
else if(l if(l>0 && r>0){
char *result1=calloc(size,1);
strcpy(result1,result);
strcat(r
gy
发帖数: 620
11
来自主题: Database版 - T-SQL 问题
对了, 你想给@result2赋值不是这么做的, 应该是:
exec sp_randomLettersGenerator @result2 out
或者用:
exec sp_randomLettersGenerator @result1 out
set @result2 = @result1

from
g*****g
发帖数: 34805
12
来自主题: Programming版 - FMP 进驻 Programming 版
Future f1 = worker1.do10seconds();
Future 22 = worker2.do15seconds();
Object result1 = f1.get();
Object result2 = f2.get();
makeUseOf(result1, result2);
This is Java built-in. And there's no 50-60-70 registration you had there.
I don't see your example simpler.
c****e
发帖数: 1453
13
来自主题: Programming版 - FMP 进驻 Programming 版
你这个get和java的future是一样的,都是block的?C# await有个很大的benefit就是
continuation.Task没有执行完也马上返回:
如果makeUseOf(result1.get(), result2.get())是个很大的函数:
result1要很久才用到,get()如果一block, 要等25秒才能进makeUseOf?

classes;
d******k
发帖数: 4295
14
来自主题: Programming版 - 一个dot net浮点运算的问题
这个不是精度的问题,是.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... 阅读全帖
c*********t
发帖数: 340
15
来自主题: Statistics版 - 求助:SAS使用问题(读数据)
macro
里面包括proc reg XXX;
ods output ParameterEstimates=result1
然后merge 之前的result和新的Result1
最后输出成一个文件
我这几天也都在做类似的事情,反正这种思路是可行的~
y****1
发帖数: 400
16
来自主题: Statistics版 - [Help] Dividing a SAS data set
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!!!!
g**********1
发帖数: 1113
17
来自主题: JobHunting版 - 做题
先把数除3,遍历result1 to 9,然后这个过程中,把(total- count)/2,遍历
result2 to count.也就是说,先确定最大的数的范围,然后确定其次大的数的范围,
然后随便遍历一下,就都出来了,可以把结果存在一个2维数组里面。
s******w
发帖数: 138
18
来自主题: BuildingWeb版 - 请教在网页里加链接的问题
我的网页在服务器的/webdata/目录下,cgi code在/webdata/cgi-bin/目录下,现在想在
网页里加入一个链接,链接指向服务器的/users/result/result1.tar.gz,目的是用户可
以点击链接下载运算结果。 但是不知道怎么让链接指向以上的文件,请大家帮忙。多谢
多谢!
o**2
发帖数: 168
19
来自主题: Programming版 - FMP 进驻 Programming 版
更正一下: 程序能立即到300行,但result1.get()要10秒才能返回, result2.get()要
等15秒。因为是并发的,所以一共要15秒,makeUseOf()就能有两个值ready了。
o**2
发帖数: 168
20
来自主题: Programming版 - FMP 进驻 Programming 版
理论上result1.get()和result2.get()是并发的,你只要等最长的那个(也就是15秒)
结束,就可以进入makeUseOf()了。
(共0页)