Show all threads Hide all threads Show all messages Hide all messages |
Where am I wrong? | alnkapa | 1214. Strange Procedure | 12 Aug 2024 03:23 | 2 |
#include <iostream> #include <algorithm> int main() { int x, y; std::cin >> x >> y; if ((x + y) & 1) { std::swap(x, y); } std::cout << x << " " << y << "\n"; return 0; } What would happen, if (x>0 && y>0) is not true? |
Math explanation | mberdyshev | 1214. Strange Procedure | 27 Mar 2020 22:02 | 2 |
We are given positive x and y. Let's go in the first loop. Let's do some method refactoring for better understanding: y0 = x*x+y; x0 = x*x+y0; y1 = sqrt(x0+(y0/labs(y0))*(-labs(y0))); for (j = 1; j <= 2*y1; j++) x0 = x0-y1; x = x0; y = y1; Let's go through the lines: y0 = x*x + y Next: x0 = x*x + y0 = 2*x*x + y As y0 > 0 (x, y are positive) => y0/labs(y0) = 1 So y1 = sqrt(x0+(y0/labs(y0))*(-labs(y0))) = sqrt(x0-labs(y0)) = sqrt(2*x*x + y - (x*x + y)) = sqrt(x*x) = x Next 2 lines equals to this: x0 = x0 - 2*y1*y1 = 2*x*x + y - 2*x*x = y So, x=y and y=x. x and y are swapped. After that you need to count amount of swaps and print appropriate answer |
For prove it just use some maths | IlushaMax | 1214. Strange Procedure | 12 Jul 2016 01:16 | 1 |
See on one iteration of "for": let be x and y on start:x1 and y1. then after each change it'll be for x1 x2...x3; for y1 y2...y3; so you have to find out x3 and y3 through x and y on start(x1 and y1); Something like that x3=y1. Good luck and sorry if my English is not enough good for explaining it) |
dunno why but I got AC XD | ძამაანთ [Tbilisi SU] | 1214. Strange Procedure | 9 Aug 2013 19:56 | 1 |
The procedure given in the problem is the solution :D my code: long x,y; cin>>x>>y; P(x,y); cout<<x<<" "<<y; XD |
i got AC but somehow i did'n understand this problem.(can you help me?) | cena | 1214. Strange Procedure | 1 Jul 2013 01:01 | 2 |
hi all; here's a bit simpler algorithm than in the question: if(x > 0 && y > 0) { for(i = 1; i <= x + y; ++i) { y = x * x + y; x = x * x + y; y = sqrt((double)x - y); x -= (2 * y * y); } } could anyone prove it to me how this scary algorithm is the one in O(1), i mean the one that tests reminders and then swap (if necessary). thank you. Edited by author 17.02.2013 15:05 Edited by author 17.02.2013 15:05 Once you've reduced it that far, you can use algebra to show that all the procedure in the for loop really does is swap the variables. That coupled with the conditions of the for loop give you the O(1) solution. Edited by author 01.07.2013 01:03 |
why??? | hoan | 1214. Strange Procedure | 20 Nov 2012 18:41 | 2 |
I got AC, but i dont understand why my code is correct, in the other word in lines: " y = sqrt(x+(y/labs(y))*(-labs(y)));"
sqrt(x+(y/labs(y)) > 0 (-labs(y))) < 0 but why when i compile this code y is positive !!! sorry for my poor english. Edited by author 15.11.2010 21:57 Re: why??? [USU] Rudnev Vladimir 20 Nov 2012 18:41 y = sqrt[x+(y/labs{y})*(-labs{y})] so (y/labs{y})*(-labs{y}) < 0 but x + (y/labs{y})*(-labs{y}) > 0 |
why? | giorgi | 1214. Strange Procedure | 17 Nov 2012 20:19 | 1 |
why? giorgi 17 Nov 2012 20:19 why is it wrong this code if (x==0 || y==0) printf ("%lld %lld",x,y); else if (x % 2 != y % 2 ) printf ("%lld %lld",y,x); else printf ("%lld %lld",x,y); |
To Admins | Fcdkbear[VNTU] | 1214. Strange Procedure | 19 Apr 2010 12:55 | 2 |
I think, the tests for this problem are not very good. In my code i forgot to check the case, where x or y are not positive, but i get AC. I think, that there must be a test case like that: -2 1. Edited by author 19.04.2010 12:55 |
idea and solution ? | Rumter (3) | 1214. Strange Procedure | 8 Nov 2008 13:38 | 1 |
(sorry my bad english) What is solution for this problem? I could not solve this problem up to the end My not finished solution: P(&x, &y) { s = x + y; for (int i = 0; i < s; ++ i) { x0 = x; y0 = y; x = y0 - 2*x0*x0; y = (int)(sqrt (2) * x0) // floor } } but I don't know what to do further. Tell me please. |
smth wrong: | looser | 1214. Strange Procedure | 24 Jun 2008 01:24 | 2 |
i have this code: <...> long x, y; <...> if( (x + y) % 2 == 0 ) printf("%ld %ld", x, y); else printf("%ld %ld", y, x); <...> and i don't check that x is > 0 and y > 0. Because "Input contains <...> output parameters of the function". so they are greater than 0! Can you explain me what is wrong? Examine the code again. if x<=0 || y<=0, value of x and y won't change. Maybe you should mention that the function never returns any value. you must output the input parameters based on the value of x and y in the last line of the function. |
why do i always got compilation error ?? | lol | 1214. Strange Procedure | 13 Dec 2007 09:54 | 2 |
#include <math.h> #include <stdio.h> void P(long x, long y) { int i, j; if (x>0 && y>0) { for (i = 1; i <= x+y; i++) { y += x*x; x = x*x+y; y = sqrt(x+(y/labs(y))*(-labs(y))); for (j = 1; j <= 2*y; j++) x = x-y; } } printf("%d %d",x,y); } int main() { long t1,t2; scanf("%ld%ld",&t1,&t2); P(t1,t2); return 0; } |
This is easy | Georgi_georgiev | 1214. Strange Procedure | 1 Nov 2007 02:19 | 2 |
This is easy this print "x y" or "y x":) Edited by author 01.11.2007 02:17 Edited by author 01.11.2007 02:18 Oh.. I didn't know what to do!!I do few programs and they didn's work.I asked my math teacher and he helped me ... |
What is wrong?... | YoD | 1214. Strange Procedure | 28 Mar 2005 19:14 | 2 |
program Project1; VAR x, y : longint; begin readln(x, y); if ((x mod 2 = 0) or (y mod 2 = 0)) and (x > 0) and (y > 0) then writeln(y, ' ', x) else writeln(x, ' ', y); end. Oh... I have found my foolish error... |
What's the meaning? | Tang RZ | 1214. Strange Procedure | 2 Jul 2004 18:53 | 4 |
If you want my program, please write to me. E-mail:trz322@yahoo.com.cn trz322@hotmail.com |
Whi wrang it avresing good in it . i chack it by given procedure and all tests is good. help please | I am david. Tabo. | 1214. Strange Procedure | 24 Oct 2002 17:13 | 3 |
var x,y:longint; begin readln(x,y); if x=y then begin writeln(x,' ',y);halt; end; if ((x mod 2= 0)and(y mod 2 = 0))or((x mod 2<>0)and(y mod 2<>0)) then begin writeln(x,' ',y);halt; end; writeln(y,' ',x); end. > var x,y:longint; > begin > readln(x,y); > if x=y then > begin > writeln(x,' ',y);halt; > end; > if ((x mod 2= 0)and(y mod 2 = 0))or((x mod 2<>0)and(y mod 2<>0)) > then > begin > writeln(x,' ',y);halt; > end; > writeln(y,' ',x); > end. |