n (A[n+1] - A[0] - 2 * Sigma(k * c[n - k + 1])) k=1 A[1] = A[0] + ---------------------------------------------- n + 1 How, did you discover this expression? > n > (A[n+1] - A[0] - 2 * Sigma(k * c[n - k + 1])) > k=1 > A[1] = A[0] + ---------------------------------------------- > n + 1 ........................................................... n ..................... (A[n+1] - A[0] - 2 * Sigma(k * c[n - k + 1])) ......................................................... k=1 A[1] = A[0] + --------------------------------------------- ...................................................... n + 1 did you mean this?? Edited by author 04.05.2007 02:46 In this problem, you can also use simply binary search, note that : A[i] = 2*(A[i-1]+C[i])-A[i-2]; At first line Cn must be replaced by Ci. Edited by author 09.02.2007 03:44 Edited by author 09.02.2007 03:44 hey WA2 why please sent me tests This is my program: var a,c:array [0..3001] of real; n:integer; procedure init; var i:integer; begin read(n); read(a[0],a[n+1]); for i:=1 to n do read(c[i]); end; function work(i:integer):real; begin if i=0 then work:=a[0] else if i=n+1 then work:=a[n+1] else work:=(work(i-1)+work(i+1))/2-c[i]; end; procedure print; begin writeln(work(1):0:2); end; begin init; print; end. Your algoritmh not correct again. It very long. This problem solve with other algoritmh. Used that a[0] = 2*a[1] + 2*c[1] - a[2] = 3*a[2] - 2*a[3] + 2*c[1] + 4*c[2], etc. this is my program: program df(input,output); var ai:array[1..3000] of integer; aj:array[1..3000] of real; c:array[1..3000] of real; i,j,n,m,k:integer; a0,an1,a1,d:real; procedure p(i,k:integer;d:real); begin if i=n+2 then begin a1:=(an1-d)/k; writeln(a1:4:2); end else begin ai[i]:=2*k-ai[i-2]; k:=ai[i]; aj[i]:=2*d+2*c[i-1]-aj[i-2]; d:=aj[i]; p(i+1,k,d); end; end; begin readln(n); readln(a0); readln(an1); for i:=1 to n do readln(c[i]); if n=0 then begin writeln(an1:4:2); halt; end; if n=1 then begin writeln(((a0+an1)/2-c[1]):4:2); halt; end; k:=2;d:=2*c[1]-a0; ai[1]:=1; aj[1]:=0; p(3,k,d); end. why i got wa??? 3 0 4 0 0 0 answer=1 ----- The sequence is: 0 1 2 3 4 thank you very much.(by geniushjs)this is my E-mail:geniushjs@tom.com program a1047; var c:array[1..3000]of longint; n,i:longint; a0,an1,a1,s:real; begin read(n); read(a0); read(an1); for i:=1 to n do read(c[i]); s:=0; for i:=1 to n do s:=s+i*c[n-i+1]; a1:=a0+(an1-a0-2*s)/(n+1); writeln(a1:0:2); end. > program a1047; > var > c:array[1..3000]of longint; > n,i:longint; > a0,an1,a1,s:real; > begin > read(n); > read(a0); > read(an1); > for i:=1 to n do read(c[i]); > s:=0; > for i:=1 to n do > s:=s+i*c[n-i+1]; This string must look like that: s:=s+c[i]*(n-1+1); > a1:=a0+(an1-a0-2*s)/(n+1); ..and this one like that a1:=(an1+n*a0-2*s)/(n+1);
> writeln(a1:0:2); > end. I think that this problem could be solved also by an approximation method. (In adition to discovering the exact expression for a[1]) The method that I offer in simplifaction look as follows: for (i=1; i<=elemNum; i++) a[i] = 0; for (j=0; j<elemNum*N; j++) { for (i=1; i<=elemNum; i++) a[i] = (a[i-1] + a[i+1]) / 2 - c[i]; printf("%.2f", a[1]); I think that after enough number of iterations it should reach the exact answer. Though, some tests that I ran with this method gave the right result, but it gave a Wrong Answer when I submitted. May be I need to make some tunnings to my method. What do you think? > I think that this problem could be solved also by an approximation > method. (In adition to discovering the exact expression for a[1]) > > The method that I offer in simplifaction look as follows: > > for (i=1; i<=elemNum; i++) > a[i] = 0; > > for (j=0; j<elemNum*N; j++) { > for (i=1; i<=elemNum; i++) > a[i] = (a[i-1] + a[i+1]) / 2 - c[i]; > > printf("%.2f", a[1]); > > I think that after enough number of iterations it should reach the > exact answer. > > Though, some tests that I ran with this method gave the right result, > but it gave a Wrong Answer when I submitted. > May be I need to make some tunnings to my method. > > What do you think? program p1047(input,output); const MAX=3000; var n,i : integer; a0,a1,an1,S : real; c : array[1..MAX] of real; begin ReadLn(n); ReadLn(a0); ReadLn(an1); for i:=1 to n do ReadLn(c[i]); if n>1 then begin S:=c[1]+c[2]; i:=3; while i<=n do begin S:=S*2.0+c[i]; i:=i+1; end; a1:=(n*a0+an1-2.0*(S+c[1]))/(n+1); end else a1:=(a0+an1)/2.0-c[1]; WriteLn(a1:6:2); end. I thought, that these 2 codes are equal: cout.precision(2); cout.setf(ios::showpoint || ios::fixed); cout<<res<<'\n'; OR printf("%0.2f",res); Can anybody explain it me. Maybe, something wrong with GNU C++? Well, it does not work always :)) I do not know why, but the truth is that on different PCs these do not work identically....... a BIG BUG But I had even a bigger problem. I submitted a solution of problem 1176 (in fact, I submitted four different solutions over 30 times ;) ), but I always got TL exceeded. I always used cin/cout. I changed cin to scanf() and cout to printf() and all was OK -> my solution got AC, having in mind that 1. When using CIN/COUT it worked over the time limit i.e. more than 2 secs 2. When I changed them to scanf/printf i got AC and my program worked 0.9 secs............ So-> I advice you -> always use printf, scanf and all the C stuff :)) C++ input/output has lots of bugs, and as it seems, it si quite slow............. which is the TIP of the of the {a0, an+1, c1, ... , cn} because my formula is correct but I still get Wrong Answer > which is the TIP of the of the {a0, an+1, c1, ... , cn} > because my formula is correct but I still get Wrong Answer Maybe your formula is wrong. It happend to me too the first time. Here is the code which solves the problem. It was accepted. for (int k=n;k>=1;k--) { a[k]=a[0]; for (i=k;i>=1;i--) a[k]-=i*2*c[i]; a[k]+=k*a[k+1]; a[k]/=k+1; }; > which is the TIP of the of the {a0, an+1, c1, ... , cn} > because my formula is correct but I still get Wrong Answer Here you are the program I have sent one more time and it was accepted. #include<stdio.h> #include<string.h> #include<stdlib.h> void main() { // FILE *f=fopen("input.txt","rt"); #define f stdin int n,i; float a[3003],c[3003]; fscanf(f,"%d",&n); memset(a,0,sizeof(a)); memset(c,0,sizeof(c)); fscanf(f,"%f %f",&a[0],&a[n+1]); for (i=1;i<=n;i++) fscanf(f,"%f",&c[i]); fclose(f); for (int k=n;k>=1;k--) { a[k]=a[0]; for (i=k;i>=1;i--) a[k]-=i*2*c[i]; a[k]+=k*a[k+1]; a[k]/=k+1; }; printf("%0.2f",a[1]); } "craiovaacm" this is the code you gave me: {Simple Calculations-1047} var a,c:array [0..3001] of real; i,n,k:integer; begin while not(eof) do begin readln(n); readln(a[0]); readln(a[n+1]); for i:=1 to n do readln(c[i]); for k:=n downto 1 do begin a[k]:=a[0]; for i:=k downto 1 do a[k]:=a[k] - I*2*c[i]; a[k]:=a[k]+k*a[k+1]; a[k]:=a[k]/(k+1); end; writeln(a[1]:0:2); end; end. I post it and get Wrong Answer, is something else wrong with the code |
|