给自己找个散分的理由。
我知道这是个初中数学问题,但你能写出一份合格的代码吗?IsTriAngle(a,b,c: Integer): boolean;请任意发挥:)
分数平分,just for fun.
我知道这是个初中数学问题,但你能写出一份合格的代码吗?IsTriAngle(a,b,c: Integer): boolean;请任意发挥:)
分数平分,just for fun.
解决方案 »
- 如何取得chart中series指针?
- 如何快速的从几千个文件中删除你想要删除的文件??关键是算法!!
- ■■■实时信息如何做?高手请进!!■■■
- 散分,十位一结,11位以后没分。需要分的同志来哪,10分钟左右一贴,不犯法吧?
- 用名字引用对象!
- 请问:为什么我升级了D7,用dbexpress连SQL2000数据库后,不能applayupdate(0)更新数据?
- ado连接SQLSERVER的问题!请帮忙!100分哦
- ComponentIdex属性的用法?
- dos下拨号问题参与者有分给出原码或例子的给一百分!
- 高手的容易题,,请进
- 为什么会出现这个错误Operator not applicable to this operand type?
- 经济危机的到来和左翼力量的兴起
begin
result:=(a+b>c) and (a+c>b) and (b+c>a) and (a>0) and (b>0) and (c>0);
end;
只判断任意一个应该就够了
的确够了。result:=(a+b>c) and (a+c>b) and (b+c>a) and (a>0);
应该不用判断 a,b,c任何一边。
a+b>c 和 a+c>b ==> 2a+b+c>b+c==> a>0
同样能得出,b>0,c>0
所以,只要判断result:=(a+b>c) and (a+c>b) and (b+c>a);
引用 2 楼 aiirii 的回复:
(a>0) and (b>0) and (c>0);
只判断任意一个应该就够了
的确够了。 result:=(a+b>c) and (a+c>b) and (b+c>a) and (a>0);
应该不用判断 a,b,c任何一边。
a+b>c 和 a+c>b ==> 2a+b+c>b+c==> a>0
同样能得出,b>0,c>0
所以,只要判断 result:=(a+b>c) and (a+c>b) and (b+c>a);
begin
{ if (a<=0)or(b<=0)or(c<=0) then
Result := false
else
Result := (a+b>c)and(a+c>b)and(b+c>a);}
Result := (a+b>c)and(a+c>b)and(b+c>a)and(a>0);
end;
var
bOk:boolean;
lwAdd:Longword;
intS:integer;begin
bOk:=true; lwAdd:=a+b;
if lwAdd=<c then
bOk:=fasle;
lwAdd:=a+c;
if lwAdd=<b then
bOk:=false;
lwAdd:=b+c;
if lwAdd=<a then
bOk:=false; intS:=a-b;
if ints>=c then
bOk:=false;
intS:=a-c;
if ints>=b then
bOk:=false;
intS:=b-c;
if ints>=a then
bOk:=false; result:=bOk;
end;
算了,先蒙一个错了也不会扣我分
function IsTriAngle(a, b, c: Integer): Boolean;
begin
Result := False;
if (a <= 0) or (b <= 0) or (c <= 0) then Exit;
if a < b then
if b - a >= c then Exit else
else if a - b >= c then Exit;
if a < c then
if c - a >= b then Exit else
else if a - c >= b then Exit;
if c < b then
if b - c >= a then Exit else
else if c - b >= a then Exit;
Result := True;
end;
楼上这牛人……
result:a+b>c,a+c>b,b+c>a.a>0,b>0,c>0(其实个人认为只判断一个就行了,这三个不等式换过来换过去,只要一个大于0,三个都大于0)
function IsTriAngle(a,b,c: Integer): boolean;
begin
result:=(a+b>c) and (a+c>b) and (b+c>a) and (a>0) and (b>0) and (c>0);
end;
如果仅仅是加法溢出的问题,那这样处理看看。(没考虑精度问题)result:=(a/2+b/2>c/2) and (a/2+c/2>b/2) and (b/2+c/2>a/2);
精度是个不可忽视的问题,a=b=c=1或a=b=2,c=1的情况就挂了。
?????????a=b=c=1,result:=(1/2+1/2>1/2) AND .....,返回是 true
a=b=2,c=1,Result:=(2/2+2/2>1/2) and ......返回是ture 也没错。这里由于除数都是2,精度误差似乎反映不出,没仔细验证,如果考虑精度问题,那就e:=0.000001;
Result:=(a/2+b/2-c/2>e) and ...........即可。
如果 a < b, 则 a + c 必定 < b
如果 a > b, 则 b + c 必定 < a
begin
result:=((a>0) and (b>0) and (c>0)) and ((a+b>c) or ((a+c>b) and (b+c>a)) ;
end; 三边都得大于零,且任有两连只和大于第三连就成。
function IsTriAngle(a,b,c: Integer): boolean;
begin
result:=((a>0) and (b>0) and (c>0)) and ((a+b>c) or ((a+c>b) or (b+c>a)) ;
end;三边都得大于零,且任有两连只和大于第三连就成。
......
var
a,b,c:integer;
d:Real;
begin
a:=StrToInt(edt1.Text) ;
b:=StrToInt(edt2.Text) ;
c:=StrToInt(edt3.Text) ;
d:=(a+b+c) / 2;
if (a<d)and(b<d)and(c<d) then lbl1.Caption:='是三角形' //每条边都要小于三边和的一半。
else
lbl1.Caption:='不是三角形';
end;
end;
然后最小两边之和大于最大的 AND 最小最大的差小于中间的