artemgf

Матрица

Jan 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. #include <set>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <stdio.h>
  9. #include <cmath>
  10. #include <math.h>
  11. #include <queue>
  12. #include <stack>
  13. #include <climits>
  14. #include <deque>
  15. #include <ctime>
  16.  
  17. using namespace std;
  18.  
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21. typedef unsigned int ui;
  22.  
  23. #define mh() make_heap()
  24. #define poph() pop_heap()
  25. #define pushh() push_heap()
  26. #define sor(n) n.begin(), n.end()
  27. #define mp make_pair
  28. #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
  29. #define p(T) pair<T,T>
  30. #define znac(l) abs(l)/l
  31. const ll ok = ll(1e9 + 7);
  32.  
  33. double cr[201][201];
  34. double uncr[201][201];
  35. double scr[201][201];
  36. int main()
  37. {
  38.     //files;
  39.     cout.precision(10);
  40.     cout.setf(ios::fixed);
  41.     ll n;
  42.     cin >> n;
  43.     for(int x=1;x<=n;x++)
  44.         for (int i = 1; i <= n; i++)
  45.         {
  46.             cin >> scr[x][i];
  47.         }
  48.  
  49.     for (int x = 1; x <= n; x++)
  50.         for (int y = 1; y <= n; y++)
  51.         {
  52.             if (x != y)
  53.             {
  54.                 if (scr[y][x] < scr[x][y])
  55.                 {
  56.                     double prom = scr[y][x];
  57.                     double mab = (scr[x][y] - prom) / 2.0;
  58.                     uncr[y][x] = (-1.0)*mab;
  59.                     cr[y][x] = mab + prom;
  60.                     uncr[x][y] = mab;
  61.                     cr[x][y] = mab + prom;
  62.                 }
  63.                 else
  64.                     if (scr[y][x] > scr[x][y])
  65.                     {
  66.                         double prom = scr[x][y];
  67.                         double mab = (scr[y][x] - prom) / 2.0;
  68.                         uncr[x][y] = (-1)*mab;
  69.                         cr[x][y] = mab + prom;
  70.                         uncr[y][x] = mab;
  71.                         cr[y][x] = mab + prom;
  72.                     }
  73.                     else
  74.                     {
  75.                         uncr[x][y] = 0;
  76.                         cr[x][y] = scr[x][y];
  77.                         uncr[y][x] = 0;
  78.                         cr[y][x] = scr[x][y];
  79.                     }
  80.             }
  81.             else
  82.             {
  83.                 cr[x][y] = scr[x][y];
  84.                 uncr[x][y] = 0;
  85.             }
  86.         }
  87.  
  88.     cout << "YES" << endl;
  89.     for (int i = 1; i <= n; i++)
  90.     {
  91.         for (int j = 1; j <= n; j++)
  92.         {
  93.             cout << cr[i][j] << " ";
  94.         }
  95.         cout << endl;
  96.     }
  97.     cout << endl;
  98.     for (int i = 1; i <= n; i++)
  99.     {
  100.         for (int j = 1; j <= n; j++)
  101.         {
  102.             cout << uncr[i][j] << " ";
  103.         }
  104.         if (i != n)
  105.             cout << endl;
  106.     }
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment