Страница 1 when you search x and y (A*x+B*y = N) use something like this for x:= 0 to min(n div a, trunc(sqrt(n))) do =) I have no idea ... If somebody've got AC, send some tests, pls Suppose: 1) A>B 2) gcd(A,B)=1 Need to find maximal A*x + B*y I try all 0 <= x <= (N-B) / A + 1 This upper limit gives AC, but is it optimal? Edited by author 18.11.2011 23:48 Given A B N D=GCD(A,B); then N/=D and N*=D and N/=D;because we must find closed number to N; A/=D; B/=D; then full search if(A>B) for(i=0;i<=N/A;i++){type here equation Ai+By=N, try to find x and y} else for(i=0;i<=N/B;i++){type here equation Ax+Bi=N , try to find x and y} *trick:in loop, if Ax+By=N then break,that means we have already found number.. Edited by author 24.03.2011 01:44 I did how you said, and when I tried to pass this solution without trick, I got TL#10, with trick got AC in 0.031 sec. I really don't understand, how this trick can give so impressive speed-up? Explain me pls!! Let's suppose A >= B, (A, B) = 1; Then there is such (0 <= i < b) that (a * i) % b = (N % b). On the other hand, i <= N / a. So, i <= min(N / a, b - 1) <= min(N / a, a - 1) <= sqrt(n); Just full search. ~O(sqrt(N)) in the worst case. To avoid TL before search do: C = GCD(A,B); A /= C; B /= C; N -= (N%C); Think why you always can do this. GOOD LUCK! thanks so much!!! Oh! I forgot, that after that N must be divided by C too :) got AC now. thanx again & HAPPY NEW YEAR!!! I need help... what is the test 7? Please tell me what is test..I m stuck at this problem for long time. Guys...please tell me..I am sure my algo is correct. Maybe overflow? I use int64 everywhere. Please tell me what test..I am stuck at this problem for long time. Edited by author 19.04.2008 02:47 Edited by author 19.04.2008 02:48 New tricky tests were added. Some authors got TL. Thanks to Boris Parfenenkov for idea of tests. Give me some test:), or may be some think wrong with test???? B can be greater than A Good Luck ^^ N'Pong Thx for your hint. from P'Moo Edited by author 07.01.2007 11:30 Thx a lot! but why goods at moderate price cost higher than "high price" good? I don't care for value of b :) First I got TL on #24 Then I got WA on #24 Are there large answer? Thanks. No. No large answer. How could it be large? Everything is quite simple. You can solve this problem occasionally, even if not think much. I try to took "j" goods for A$ and goods for B$ on rest money. Then I try to took "j" goods for B$ and goods for A$ on rest money. 0<="j"<=min(n/a,b) What's wrong? My single idea :my code can generate negative numbers as answer. I don't understand anything... I really can't understand why i recieved WA on 1th test. I'm sure in my solution and i pass all my tests. Please give me some additional tests. Now i'm getting WA 43:( Edited by author 16.02.2006 00:12 Edited by author 16.02.2006 16:41 [code deleted] Edited by moderator 11.02.2006 17:32 thats true! there's no problem. it just cant pass test #9 what is test #9? all my tests go good. Give a hint, please. misha ne pravil'no reshaesh', poprobyi mozgami poshevelit'! esli kone4no oni est':) I've got TL #9 then WA #24 GIVE ME SOME TEST!!!!!! I STILL HAVE WA#2!!!!!!!!! [code deleted] this right? Edited by moderator 22.02.2006 00:38 var a,b,n,k1,k2:longint; begin readln(a,b,n); while n>=a do begin n:=n-a; k1:=k1+1; end; while n>=b do begin n:=n-b; k2:=k2+1; end; writeln(k1,' ',k2); end. земляк помоги решить 10 задачу или проверь 8 5 10 Answer: 0 2 Do you check if N=0?? sorry for doublepost Edited by author 11.02.2006 16:13 My answer is 0 0. Whay it does not work too? (WA#2) var a, b, n: LongInt; x,y,xo,yo,q,w: LongInt; begin Read(a, b, n); x := n div a; xo := n mod a; y := n div b; yo := n mod b; q := x * a + xo div b * b; w := y * b + yo div a * a; If q >= w then WriteLn(x, ' ', xo div b) Else WriteLn(yo div a, ' ', y); end. 47 3 49 ans: 0 16 2 3 7 ans: 2 1 It is not guaranteed that A >= B and 2 test checks this. AFAIK if you will throw error if B > A, then you will get Runtime Error on test 2. Edited by author 06.03.2024 16:54 Who solved it. GIVE ME SOME TEST PLEASE!!!!!!! GIVE ME SOME TEST PLEASE!!!!! Give me some test please!!!!! I've got WA!!! Edited by author 11.02.2006 14:28 2 5 89 My output is '2 17'. It is correct, but still WA#2. |
|