二次函数闭区间求最小值、、

某题目出错了,然后就写了个错的、

觉得很可惜,就粘过来、、

 自己感觉挺对的、、

 

 1 Var
 2   l,r,a,b,c,n,i:longint;
 3   x,xx,Iris:Extended;
 4 Begin
 5   Read(L,r);
 6   Iris:=-1*Maxlongint;
 7   Read(a,b,c);
 8   if a=0 Then
 9     Begin
10       if b<0 Then xx:=b*r+c
11       Else xx:=a*l*l+b*l+c;
12     End
13   Else if a>0 Then
14     Begin
15       x:=-0.5*b/a;
16       if x<0 Then
17         xx:=c+a*l*l+b*l
18       Else if x>r Then xx:=a*r*r+r*b+c
19       Else xx:=c-b*b/(4*a);
20     End
21   Else
22     if a<0 Then
23       Begin
24         x:=-0.5*b/a;
25         if x<0 Then xx:=a*r*r+r*b+c
26         Else if x>r Then xx:=c+a*l*l+b*l
27         Else
28           Begin
29             if x<r-x Then xx:=a*r*r+r*b+c
30             Else xx:=c+a*l*l+b*l;
31           End;
32       End;
33   Iris:=xx;
34   Writeln(Iris:0:4);
35 End.

 

posted @ 2013-11-06 17:22  Iris.Catch-22.S、`  阅读(266)  评论(0编辑  收藏  举报