Show all threads Hide all threads Show all messages Hide all messages | Give you some testcases,maybe can help you | Hakkinen | 1066. Garland | 21 Jul 2023 17:45 | 3 | 999 987.23 answer 934270.79 3 100 answer 0.00 4 1000 answer 0.00 5 12 answer 0.00 thank you. Try this if you have WA3. | What is the easiest way to solve this problem?(I have already got AC) | Ярославцев Григорий | 1066. Garland | 24 Jun 2013 14:19 | 9 | My solution uses binary search to find such height for second lamp that garland is never under the floor and this height is the lowest possible. For checking that garland is never under the floor I use simple O(N). I have used a simulation method, first I have built that garland thinking that second lamp is at the same height as first, then Ive calculated then minimum of i*H[i] and lowered the garland by the result, and the resulted height of Nth lamp was the answer. Overall O(n) I think. I like the idea of binary search, but I check that garland is never under the floor in O(1). It easily can be proved, that the garland has an equation x*x+p*x+A. p is a parameter of binary search. Also it's known, that such a parabola(defined in integer points only) has minimum in floor(0.5-p/2). So the checking is very easy. Edited by author 27.07.2004 14:40 Knowing that the form of the garland is parabola and knowing exact solution for h[i], it is very easy to check minimal B: n--; for(i=1;i<n;i++) if((tmp=(n-i)*(n*i-a)/i) >b) b = tmp; That's all! b is answer! It is short. But while you will think about a garland's form, I will have written a solution, based on binary search. In real competition it is better. Actually,we can get the formula by mathematical induction very easily.We can see: h1=h1, h2=h2, Since hn+1=2hn-h(n-1)+2, so we can find: h3=2h2-h1+2, h4=3h2-2h1+6, h5=4h2-3h1+12, and by mathematical induction,not difficult to prove: hn=(n-1)h2-(n-2)h1+n(n+1). Thus we can trace every hi>0 and get the minimum for h2 and then we can find hn. Guys why this cleverness. Binary search - is solution that author recognized I think. But about parabolf thinking is good idea - you're clever boys ;) I have change h2 to h, h1 to A and n to x. Then i have get something like x^2+bx+c. hn>0 if that formula ax^2+bx+c>=0. Its possible only if D<=0. I have found and get the othe formula but now with h like h^2+bh+c. After that i have found h1 and h2, and choose the smallest bigger than 0. And that result i have written in the first formula, and have found B. But the problem that my result is different from the real, but not very much. its my code: #include <stdio.h> #include <math.h> int main() { int N,i; double h1,h2,A,B,min; scanf("%d%lf",&N,&A); h1=A+1.0+2*sqrt(A); h2=A+1.0-2*sqrt(A);; if(h2<h1&&h2>0) min=h2; else min=h1; B=(N-1)*min-(N-2)*A+(N-1)*(N-2); printf("%0.2lf",B); return 0; } PS sorry for my English Edited by author 27.06.2008 02:38 a2=(1/2)a1 + (1/2)a3 -1 a3=(1/3)a1 + (2/3)a4 -2 a4=(1/4)a1 + (3/4)a5 -3 ... an=(1/n)a1 + ((n-1)/n) a(n+1) - (n-1) Just by putting a2 into a3's initial formula a3=(1/2)(a2+a4) -1 and so on, you can get the relationship of an and a(n+1), then you can guess An, and calculate the whole sequence. As long as ai>=0, An can be lower, in this way you'll get the answer. | My O(1) solution | Wang Xiang | 1066. Garland | 27 Jul 2009 20:31 | 1 | And,here it is: program wx; var i,j,k,m,n:longint; b,c,s,t:extended; begin readln(n,c); dec(n); m:=trunc(sqrt(c)); if m>=n then begin writeln('0.00'); exit; end; if c/m<=m+1 then begin b:=m+c/m; s:=n*n-b*n+c; end else s:=1e100; inc(m); if c/m>=m-1 then begin b:=m+c/m; t:=n*n-b*n+c; end else t:=1e100; if s<t then writeln(s:0:2) else writeln(t:0:2); end. | Why my program can not be accepted?? | Danli | 1066. Garland | 20 May 2009 11:16 | 1 | #include<iostream.h> #include<math.h> int ji(int n); int main() { int k,n,m,c,a; int d=0; cin>>n>>k; if((k>=2&&k<=10)&&n>=2&&(n+k)<=18) { m=0; if(n%2==1) while(m<(n+1)/2) { c=ji(n-m); a=ji(m); d=d+int(pow(k-1,n-m-1)*c/a/ji(n-m-m)); m++; } else while(m<=(n+1)/2) { c=ji(n-m); a=ji(m); d=d+int(pow(k-1,n-m-1)*c/a/ji(n-m-m)); m++; } cout<<(k-1)*d<<endl; } return 0; } int ji(int n) { if(n==0) return 1; else return n*ji(n-1); } | new solution!!! | kirara1988 | 1066. Garland | 8 Mar 2009 13:23 | 1 | H(i+1)-H(i)=H(i)-H(i-1)+2; denote d(i)=H(i+1)-H(i) you can get: d(i)=d(i-1)+2; H(N)-H(1)=(N-1)d(1)+(N-1)(N-2); H(i)-H(1)=(N-1)d(i)+(i-1)(i-2); according to the above two equation, denote H(i)=0 you will get:H(N)=(N-i)*((N-1)-H1/(i-1)); the maximun of H(N) is the answer .so strange! Edited by author 08.03.2009 15:00 Edited by author 08.03.2009 15:00 | So faint! I feel thrte is a O(1) algo & AC, but I don't understand, can someone tell me why? | wrbuaa2005 | 1066. Garland | 4 Sep 2008 18:19 | 1 | After I get the function f(N)= N*N+a*N+(A-a-1), I solve f(a/2)=0 getting value of a, after that I find the two integar s1 s2 nearest to a and let f(s1) = 0 || f(s2) = 0 to min this function. An exception is a/2 > the N given by this problem, in this case it should be 0 | I do not understand | Muhamed | 1066. Garland | 30 May 2008 00:19 | 2 | please send me the solution of this question muhamed@netmail.kg If you have trouble with understanding the English of the problem, see alternate translations at my website. If you have trouble with algorithm of the problem, consider finding a formula for H_i in terms of H_1 and H_2, or better yet in terms of H_1 and d = H_2 - H_1. | I think the test 5 may be wrong | chnlkw | 1066. Garland | 28 Mar 2008 20:14 | 1 | It says that "no lamp in the garland lies on the ground ", it means that h[i] and h[i+1] can't be both 0 at the same time. if my program considers it ,it got WA on #5,but it got AC when i ignore it. I have seen a AC program which doesn't care about the condition. Am i wrong? | Binary Search Algo | jagatsastry | 1066. Garland | 1 Dec 2007 02:27 | 1 | Can anyone just explain in slight detail about how binary search can be used to solve this problem. | Small Trick | Spatarel Dan Constantin | 1066. Garland | 30 Nov 2007 13:09 | 5 | There is a small trick at this problem. Whoever gets WA, should try this test: 30 1000 The right answer is 0.00 My AC programs write 1000.00 ... Correct answer for test 30 1000 is 0.00. I have AC with O(1) algorithm. My AC prog also tells 0.00 Thanks a lot! Now I get AC. | Binary Search AC program | Bogdan A. Stoica [fireatmyself] | 1066. Garland | 18 Nov 2007 21:33 | 2 | #include <stdio.h> #define eps 0.00000001 double A, B=((1<<31)-1), DMin=((1<<31)-1); int N; void bs() { double p1 = A, p2 = 0, mij, a1, a2, a3, min; int i; while ((p1-p2)>eps) { min = A; mij = (p1+p2)/2; a1 = A; a2 = mij; for (i = 2; i < N; i++) { a3 = 2*(a2+1)-a1; a1 = a2; a2 = a3; if (a3 < 0) { p2 = mij+eps; break; } else if (min > a3) min = a3; } if (i == N) { if ((B-a3)<eps) p2=2*p1; if ((DMin-min) > eps) DMin = min, B = a3; p1 = mij-eps; } } } int main() { scanf("%d %lf", &N, &A); bs(); printf("%.2lf\n", B); return 0;
} Can you just explain in simple terms the method you've used. Edited by author 01.12.2007 02:29 | I don't understand question | Remington OKTL | 1066. Garland | 27 Jun 2006 19:29 | 3 | English: It's said that H[i]=(H[i-1]+H[i+1])/2, but we know only height of first lamp, so when we try to determine height of second lamp, where from do we take H[3] ??? Don't I unterstand question right ??? Please explain me, if you can. Exactly same text in Russian: Сказано, что H[i]=(H[i-1]+H[i+1])/2, но мы знаем только высоту первой лампочки, а когда мы определяем высоту второй лампочки откуда брать высоту третей H[3] ??? Или я не совсем правильно понял вопрос ??? Объясните кто-нибудь, пожалуйста. Edited by author 18.01.2006 18:04 We should minimize height of the last lamp. Of course each lamp can be at different heights. H[3]=H[2]*2-H[1]. | Why I got WA #1.....I test many times.... | weep | 1066. Garland | 15 Mar 2005 02:26 | 2 | This is my code: {$N+} program u1066; var n,i:longint; a1,an,tmp:extended; begin readln(n,a1); for i:=3 to n do begin tmp:=(a1-i+1)*(i-2)/(i-1); if tmp>an then an:=tmp; end; an:=(n-1)*an+(n-1)*(n-2)-(n-2)*a1; if an<0 then an:=0; writeln(an:0:2); end. I tried these: 100 100 =>7921.00 10 11 =>32.00 123 456 =>10128.86 111 111 =>9891.00 8 15 =>9.75 5 10 =>0.67 70 50 =>3835.14 1000 1=>996004.00 | What should be output when n=3 or 4? | NewComer | 1066. Garland | 16 Aug 2004 17:28 | 1 | | why i keep getting WA??help | wangchun | 1066. Garland | 26 Jul 2004 09:38 | 4 | I've tried every tests i could found. It's all right. But i keep getting WA. This is my program: var t,n,l:integer; a:real; sz:array[1..1000]of record x:integer; n:real; end; x,min,k:real; q:boolean; begin readln(n,a); fillchar(sz,sizeof(sz),0); sz[1].n:=a; sz[2].x:=1; for t:=3 to n do begin sz[t].x:=sz[t-1].x*2-sz[t-2].x; sz[t].n:=(sz[t-1].n+1)*2-sz[t-2].n; end; min:=-1; for t:=2 to n-1 do begin x:=(-sz[t].n)/sz[t].x; q:=true; for l:=2 to n do begin k:=sz[l].x*x+sz[l].n; q:=q and(k>=0); end; k:=sz[n].x*x+sz[n].n; if ((k<min)or(min=-1))and(q) then min:=k; end; writeln(min:0:2); end. About your code: i don't know, sorry About problem: there is simple solution O(1), about 12 strings... So can you tell the O(1) solution and if possible explain it ? Thank you. My O(n) solution (I used maths)is 15 strings but I don't know there is a O(1) solution.Please explain it. | Binary search, WA on test #7. Why? | Maigo Akisame | 1066. Garland | 23 Jun 2004 04:18 | 5 | program ural1066; var n,i:integer; a,b,c,l,r,h2:real; h1:real; begin readln(n,h1); l:=0;r:=maxlongint; repeat b:=h1; h2:=(l+r)/2;c:=h2; for i:=3 to n do begin a:=b;b:=c;c:=2*(b+1)-a; if c<0 then break; end; if c<0 then l:=h2 else r:=h2; until r-l<1e-4; writeln(abs(c):0:2); end. You should use math to solve this problem When I inputed 1000 1, my prog gave me 996004.06. So I knew it was the prob of accuration. But when I changed '1e-4' in the last line but two into '1e-10', it worked well on my PC, but WA test #1 on the judge! It's even stranger! You solutions is not correct.You can try these test: 100 100 =>7921.00 10 11 =>32.00 123 456 =>10128.86 111 111 =>9891.00 8 15 =>9.75 5 10 =>0.67 70 50 =>3835.14 1000 1=>996004.00 (It was given by an ACed program) If you don't know how to solve this problem by maths I can tell you. I used only 9 var and 12 lines program, O(N). Goodluck!:) | Please give me some test | Harmy | 1066. Garland | 2 Jun 2004 14:50 | 1 | Help!I use binary search to find the answer. Please give me some test! Thanks {my wrong mode here} const maxn=1000; maxm=1000000; var a1,n:longint; ta1:real; a:array[1..maxn]of extended; procedure init; begin { assign(input,'1066.in'); reset(input);} readln(n,ta1); a1:=round(ta1*maxm); a[1]:=a1; end; procedure search(first,last:longint); var cha1,cha2:real; h,h1,h2:longint; function solve(x:longint):boolean; var te,i,j:longint; begin i:=2; a[2]:=x; solve:=true; repeat inc(i); a[i]:=2*(a[i-1]+maxm)-a[i-2]; if a[i]<0 then begin solve:=false; exit; end; until a[i]>a[i-1]; dec(I); if first=last then begin for j:=i+1 to n do a[j]:=2*(a[j-1]+maxm)-a[j-2]; writeln((a[n]/maxm):0:2); halt; end; end; begin h:=(first+last) div 2; if solve(h) then search(first,h) else search(h+1,last); end; begin init; search(0,a1); end. | some questions | aa | 1066. Garland | 26 Feb 2003 20:00 | 3 | if the input is 5 10,whats the answer? if there is no solutions to the input,how to do with it? > if the input is 5 10,whats the answer? 0.67 > if there is no solutions to the input,how to do with it? there will always be a solution! Thanks,I've got AC. But there is a strange wrong in my prog: I calculate this expression in my delphi compiler: (4/3+1)*2-14/3 the result was 4.337e-19.But it should be zero. can you tell me why? | Who can tell me why my programme is wrong? It seem to be so simple and I think is should be right. | Bolin, Ding | 1066. Garland | 20 Oct 2002 18:36 | 1 | #include<stdio.h> //Who can tell me why my programme is wrong? It seem to be so //simple and I think is should be right. #define Max(a,b) (a>b?a:b) typedef long double type; double N; type H1,H2; int main() { float a; type i; scanf("%lf %f",&N,&a); H1=(type)a; H2=0; for (i=2; i<=N; i++) H2=Max(H2,(H1*(i-2)-(i-1)*(i-2))/(i-1)); printf("%0.2lf\n",(double)Max(0,H2*(N-1)-H1*(N-2)+(N-1)*(N-2))); return 0; } | the sample is wrong ,isn't it? | Lin Zi | 1066. Garland | 18 Nov 2001 12:21 | 2 | |
|
|