8475.009765625 3721.89990234375 3455 my answer is : 17925655.52 2916 539 for 8475.00 3721.89 3455 i have the answer 17925621.65 2916 539 First answer is correct (I mean, my program that is AC, gives the same result :)) Answer for 2nd test should look like this: 17925621.71 2916 539 Probably you have some rounding problems (in your answer two digits after decimal point are incorrect). No, you can't. Because K>=1, which means you must produce at least one you are wrong. loook at this. "the total amount of produced goods must not exceed K pieces" it can be 0. :)good luck. const max=10000; var a,b,out,temp:real; k,t,al,bl,m,n:integer; s1,s2:array[0..max]of real; begin readln(a,b); readln(k); al:=-1; bl:=-1; for t:=1 to k do begin s1[t]:=a*t-t*t; s2[t]:=b*t-t*t; if (s1[t]<=s1[t-1])and(al=-1) then al:=t-1; if (s2[t]<=s2[t-1])and(bl=-1) then bl:=t-1; if (al<>-1)and(bl<>-1) then break; end; if al+bl<=k then begin out:=s1[al]+s2[bl]; writeln(out:0:2); writeln(al,' ',bl); halt; end; m:=0; n:=0; out:=0; for t:=k-bl to al do begin temp:=s1[t]+s2[k-t]; if temp>out then begin out:=temp; m:=t; n:=k-t; end; end; writeln(out:0:2); writeln(m,' ',n); end. Input: 5434.87 -4567 300 Correct output: 1540461.00 300 0 Your output: 0.00 -1 0 It is wrong. I'm trying all combinations of horns and hoofs amount which sum is not larger than K, calculating its profit and store minimal. The direction of bruteforce should give least amount of horns and hoofs if there are equal profit for several combination. Of course I should use simple calculation instead of bruteforce, but why my stupid program got WA (not time limit) on test 7 ? ;) There are some tests(-4 -7 10) when the answer is minus values. The text of problem is obscure and i don't know what to do. I always have WA. It annoys me a bit! This is my program: why i got WA var b1,b2,func,cf:real; k,step,a1,a2,i1,i2,t,aa1,aa2:longint; begin step:=10000; a1:=5000; a2:=5000; cf:=0; readln(b1,b2); readln(k); for t:=1 to 4 do begin step:=step div 10; i1:=a1-6*step; while i1<=a1+6*step do begin i2:=a2-6*step; while i2<=a2+6*step do begin if (i1+i2<=k)and(i1>=0)and(i2>=0) then begin func:=i1*b1+i2*b2-i1*i1-i2*i2; if func>cf then begin cf:=func; aa1:=i1; aa2:=i2; end; end; i2:=i2+step; end; i1:=i1+step; end; a1:=aa1; a2:=aa2; end; writeln(cf:0:2); writeln(a1,' ',a2); end. My algorithm is about Binary Search. #include <stdio.h> int main() { float a,b,m=0; long n,l,l2,lf,rg,c,k; float m1=0,m2=0; FILE* fname=stdin; FILE* fout=stdout; fscanf(fname,"%f%f%ld",&a,&b,&n); for (l=0; l<=n; l++) { if (l>0) if ( (l*l)-(l-1)*(l-1) >= a ) break; lf=1; rg=n-l; c=(lf+rg)/2; k=0; for (; lf<=rg; c=(lf+rg)/2) { if ( (c*c)-(c-1)*(c-1) < b ) { k=c; lf=c+1; } else rg=c-1; } if ( (l*a)+(k*b) - (l*l+k*k) > m ) { m=(l*a)+(k*b) - (l*l+k*k); m1=l; m2=k; } } m=(m1*a)+(m2*b) - (m1*m1+m2*m2); if (m==0) m=0; fprintf(fout,"%.2f\n%.0f %.0f\n",m,m1,m2); fclose(fname); fclose(fout); return 0; } I've got trouble in 1200. Help me please. Here is my programme: {$n+} const zero=1e-5; var k,c,d,e,f:longint; a,b,max,g:extended; begin assign(input,''); reset(input); assign(output,''); rewrite(output); read(a,b); read(k); max:=-1e10; for c:=0 to k do begin d:=round(b/2); if d<0 then d:=0; if c+d>k then d:=k-c; g:=-sqr(d)+b*d+a*c-sqr(c); if g>max-zero then begin max:=g; e:=c; f:=d; end; end; writeln(max:0:2); writeln(e,' ',f); close(input); close(output); end. Thank you very much! {$n+} const zero=1e-20; var k,c,d,e,f:longint; a,b,max,g:extended; begin assign(input,''); reset(input); assign(output,''); rewrite(output); read(a,b); read(k); max:=-1e10; for c:=0 to k do begin d:=round(b/2); if d<0 then d:=0; if c+d>k then d:=k-c; g:=-sqr(d)+b*d+a*c-sqr(c); if g>max-zero then begin max:=g; e:=c; f:=d; end; end; writeln(max:0:2); writeln(e,' ',f); close(input); close(output); end. Use trunc, not round. Don't use const zero, only need " if g > max ". I'm sure you'll get AC > Use trunc, not round. > Don't use const zero, only need " if g > max ". > I'm sure you'll get AC I am very sorry that you can proceduce 0 Horn and 0 Hoof! sorry,but i don't think so. i've seen an ac problem,and it allows 0 0 I've compared it with an AC program and tested many cases,but still can't find anything wrong.But when I submit,it says WA.Please help me! [code deleted] Edited by moderator 06.12.2019 21:38 [code deleted] Edited by moderator 06.12.2019 21:39 You should change "if (a-sqr(i+1)+sqr(i)<0)and(b-sqr(j+1)+sqr(j)<0) then break;" into "if (a-sqr(i+1)+sqr(i)<=0)and(b-sqr(j+1)+sqr(j)<=0) then break;",and your program will gets AC.
34.20 61.70 10000 > 34.20 61.70 > 10000 1244.10 17 31 {This is my program} program URAL1200; var a,b,xx,max:real; c,k,x,y:longint; bestx,besty:longint; begin read(a,b,k); max:=0; bestx:=0; besty:=0; for c:=1 to k do begin xx:=(2*c+a-b)/4; if xx<0 then xx:=0; if xx>c then xx:=c; x:=round(xx-0.001); y:=c-x; if a*x+b*y-x*x-y*y>max then begin max:=a*x+b*y-x*x-y*y; bestx:=x; besty:=y; end; end; writeln(max:0:2); writeln(bestx,' ',besty); end. #include <stdio.h> #include <math.h> long double A, B; int K; int Ba, Bb; long double Best; #define eps 0.001 void solve() { long double p, pb; int a, b; for (a = K, b = 0, pb = 0; a >= 0; a--) { p = (K-a)*(B - K+a); if (p > pb+eps) pb = p, b = K-a; p = a*(A - a) + pb; if (p > Best-eps) Best = p, Ba = a, Bb = b; } } void main() { scanf("%Lf %Lf %d", &A, &B, &K); solve(); printf("%.2Lf\n%d %d\n", Best, Ba, Bb); } type Sum = record Rub, Kop:LongInt; end; var A, B:Sum; K:LongInt; procedure Inp; var _A, _B:Extended; begin Read(_A, _B); A.Rub:=Round(_A*100) div 100; A.Kop:=Round(_A*100) mod 100; B.Rub:=Round(_B*100) div 100; B.Kop:=Round(_B*100) mod 100; Read(K); end; procedure Profit(Coeff:Sum; Count:LongInt; var P:Sum); begin P.Rub:=Count*(Coeff.Rub-Count)+(Count*Coeff.Kop) div 100; P.Kop:=(Count*Coeff.Kop) mod 100; end; function FindMax(V:Sum):LongInt; var P, Bp:sum; I, Max:LongInt; begin FillChar(Bp, Sizeof(Bp), 0); for I:=0 to K do begin Profit(V, I, P); if (P.Rub>Bp.Rub) or ((P.Rub=Bp.Rub) and (P.Kop>Bp.Kop)) then begin Max:=I; BP:=P; end; end; FindMax:=Max; end; var BX, BY:LongInt; BP:Sum; procedure Run; var Xmax, Ymax:LongInt; X, Y:LongInt; P, Py:Sum; I, J:LongInt; begin FillChar(Bp, Sizeof(BP), 0); Xmax:=FindMax(A); Ymax:=FindMax(B); for I:=0 to K do begin X:=I; if (X>XMax) then X:=XMax; Y:=K-I; if (Y>YMax) then Y:=YMax; P.Rub:=0; P.Kop:=0; Profit(A, X, P); Profit(B, Y, Py); P.Rub:=P.Rub+Py.Rub+(P.Kop+Py.Kop) div 100; P.Kop:=(P.Kop+Py.Kop) mod 100; if (P.Rub>BP.Rub) or ((P.Rub=Bp.Rub) and (P.Kop>Bp.Kop)) then begin BP:=P; BX:=X; BY:=Y; end; end; end; procedure Out; begin Write(Bp.Rub, '.'); if (BP.Kop<10) then Write(0, BP.Kop mod 100) else if (BP.Kop mod 100=0) then Write('00') else Write(BP.Kop mod 100); WriteLn; WriteLn(Bx, ' ', BY); end; begin { Assign(Input, 'Input.txt'); Reset(Input);} Inp; Run; Out; { Close(Input);} end. |
|