fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. /**
  10.  * Auto-generated code below aims at helping you parse
  11.  * the standard input according to the problem statement.
  12.  **/
  13. int main()
  14. {
  15. string c;
  16. getline(cin, c);
  17.  
  18. int m;
  19. cin >> m; cin.ignore();
  20.  
  21. double x, y;
  22.  
  23. int idx = c.find_first_of("+");
  24.  
  25. if(idx != string::npos) {
  26. x = stod(c.substr(0, idx));
  27. y = stod(c.substr(idx + 1, c.length() - 1));
  28. } else {
  29. idx = c.find_last_of("-");
  30. x = stod(c.substr(0, idx));
  31. y = stod(c.substr(idx, c.length() - 1));
  32. }
  33.  
  34. int cnt = 0;
  35. double fx = 0.0;
  36. double fy = 0.0;
  37.  
  38. double a = x;
  39. double b = y;
  40.  
  41. while(cnt < m) {
  42. cnt++;
  43. double v = a * a + b * b;
  44. if(v * v > 4.0) break;
  45.  
  46. a = fx * fx - fy * fy + x;
  47. b = 2 * fx * fy + y;
  48.  
  49. fx = a;
  50. fy = b;
  51. }
  52.  
  53. cout << cnt << endl;
  54. }
Success #stdin #stdout 0s 4508KB
stdin
-0.65812-0.452i
275
stdout
124