fork download
  1. #define task "CONSTRUCT"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <iomanip>
  6. #include <cassert>
  7.  
  8. using namespace std;
  9.  
  10. using ll = long long;
  11. using ld = long double;
  12.  
  13. constexpr int N = 1e5 + 5;
  14. int n;
  15. ll x[N], y[N];
  16. ld a[N], b[N];
  17.  
  18. void Read()
  19. {
  20. cin >> n;
  21.  
  22. for (int i = 1; i <= n; ++i)
  23. cin >> x[i] >> y[i];
  24. }
  25.  
  26. ld SolveEquation(ll c1, ll c2)
  27. {
  28. // assert(!((c1 + c2) & 1));
  29. return (ld)1.0 * (c1 + c2) / 2;
  30. }
  31.  
  32. void Cal(ll x[N], ld a[N], int n)
  33. {
  34. ll tmp = 0;
  35.  
  36. for (int i = 1; i < n; ++i)
  37. if (i & 1)
  38. tmp = tmp + x[i] * 2;
  39. else
  40. tmp = tmp - x[i] * 2;
  41.  
  42. a[1] = SolveEquation(x[n] * 2, tmp);
  43.  
  44. for (int i = 2; i <= n; ++i)
  45. a[i] = x[i - 1] * 2 - a[i - 1];
  46. }
  47.  
  48. void Constrain_4(ll x[N], ld a[N])
  49. {
  50. ld I2 = (x[1] + x[2]) / 2.0,
  51. I3 = (x[2] + x[3]) / 2.0,
  52. I4 = (x[3] + x[4]) / 2.0,
  53. I1 = (x[4] + x[1]) / 2.0,
  54. I = (x[1] + x[3]) / 2.0;
  55.  
  56. // a_1 + I = 2I1 => a_1 = 2I1 - I
  57.  
  58. a[1] = 2 * I1 - I;
  59. a[2] = 2 * I2 - I;
  60. a[3] = 2 * I3 - I;
  61. a[4] = 2 * I4 - I;
  62. }
  63.  
  64. void Solve()
  65. {
  66. if (n == 4)
  67. {
  68. Constrain_4(x, a);
  69. Constrain_4(y, b);
  70.  
  71. for (int i = 1; i <= n; ++i)
  72. cout << fixed << setprecision(2) << a[i] << " " << b[i] << "\n";
  73. }
  74. else
  75. {
  76. Cal(x, a, n);
  77. Cal(y, b, n);
  78.  
  79. for (int i = 1; i <= n; ++i)
  80. cout << fixed << setprecision(2) << a[i] << " " << b[i] << "\n";
  81. }
  82. }
  83.  
  84. int32_t main()
  85. {
  86. ios::sync_with_stdio(0);
  87. cin.tie(0);
  88. cout.tie(0);
  89. if (fopen(task ".INP", "r"))
  90. {
  91. freopen(task ".INP", "r", stdin);
  92. freopen(task ".OUT", "w", stdout);
  93. }
  94.  
  95. Read();
  96. Solve();
  97. }
  98.  
Success #stdin #stdout 0s 5932KB
stdin
3
5 2
3 6
6 4
stdout
8.00 0.00
2.00 4.00
4.00 8.00