一个让我蛋疼好几天也没算出来的算法 本帖最后由 m3905 于 2013-09-25 08:37:53 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Var I,J,K:Double;begin I := StrToFloat(Edit1.Text); J := ((0.1 + (10000 - I)) * (0.2) / 9999) * I; Label1.Caption := FloatToStr(J);end;感谢回复 貌似不对 在I=1的时候 数值并不是0.3 10000的时候 也不等于3000 晕啊 ((0.1 + (10000 - I)) * (0.2) / 9999) * II等于1的时候,(0.1 + 9999 * 0.2 /9999) * 1 ,约分实际计算会有误差的,同理可得10000,J是1000 Quote: 引用 3 楼 m3905 的回复:Var I,J,K:Double;begin I := StrToFloat(Edit1.Text); J := (0.1 + (10000 - I) * (0.2) / 9999) * I; Label1.Caption := FloatToStr(J);end; I := StrToFloat(Edit1.Text);改为I := random(10000)+1; // 特殊情况 单独考虑function RanIJ( ):string;var tmp, v1, v2, cv: double;begin randomize(); cv := random(); v1 := 10000*(1 - cv); if cv < 0.5 then begin tmp := v1 * 0.3 - cv*v1*0.2; end else tmp := v1 * 0.1 + cv*v1*0.2; result := floattostr(v1) + ',' + floattostr(tmp);end; 这个BMP.FREE为什么出错? 面试的问题,如何在文件属性框中增加一页自定义的面板,并在该面板上放一页图片?? 为什么会错呢?Undeclared identifier: 'FormCloseQuery' 时间如何转换为浮点数? 请问下面的insert语句为什么不对?? 一篇好文章 如何判断文件被独占? 为什么不能创建模式空体? 我想对文件中的数据进行统计 如何将bmp文件压缩成jpg文件?delphi里有现成的控件或类吗? 明基(BENQ)15”液晶显示器电脑RMB2999促销,有需要的朋友请联系我(东莞) 請問 Delphi 如何拋出例外呢?
begin
I := StrToFloat(Edit1.Text);
J := ((0.1 + (10000 - I)) * (0.2) / 9999) * I;
Label1.Caption := FloatToStr(J);
end;感谢回复 貌似不对 在I=1的时候 数值并不是0.3 10000的时候 也不等于3000 晕啊
同理可得10000,J是1000
改为
I := random(10000)+1;
function RanIJ( ):string;
var
tmp, v1, v2, cv: double;
begin
randomize();
cv := random();
v1 := 10000*(1 - cv);
if cv < 0.5 then
begin
tmp := v1 * 0.3 - cv*v1*0.2;
end
else
tmp := v1 * 0.1 + cv*v1*0.2;
result := floattostr(v1) + ',' + floattostr(tmp);
end;