Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int mx(int **arr, int& N, int& M)
  7. {
  8.     int max;
  9.     max = arr[0][0];
  10.  
  11.     for (int i = 0; i < N; i++)
  12.     {
  13.         for (int j = 0; j < M; j++)
  14.         {
  15.             if (arr[i][j] >= max)
  16.             {
  17.                 max = arr[i][j];
  18.             }
  19.         }
  20.     }
  21.     return max;
  22. }
  23.  
  24. int neg_Q(int** arr, int& N, int& M)
  25. {
  26.     int neg_Q;
  27.     neg_Q = 0;
  28.  
  29.     for (int i = 0; i < N; i++)
  30.     {
  31.         for (int j = 0; j < M; j++)
  32.         {
  33.             if (arr[i][j] < 0)
  34.             {
  35.                 neg_Q++;
  36.             }
  37.         }
  38.     }
  39.     return neg_Q;
  40. }
  41.  
  42. int R(int rad)
  43. {
  44.     int p_q = 0;
  45.    
  46.         int x = 1, y = 1;
  47.         while (x <= rad)
  48.         {
  49.             while (y <= rad)
  50.             {
  51.                 if (pow(x, 2) + pow(y, 2) <= pow(rad, 2))
  52.                 {
  53.                     p_q++;
  54.                 }
  55.             }
  56.         }
  57.         p_q *= 4;
  58.         p_q++;
  59.         p_q += 4 * ceil(rad);
  60.     return p_q;
  61. }
  62.  
  63. int main()
  64. {
  65.     int N, M;
  66.     cin >> N >> M;
  67.    
  68.     int** arr = new int* [N];
  69.     for (int i = 0; i < N; i++)
  70.     {
  71.         arr[i] = new int[M];
  72.     }
  73.  
  74.     for (int i = 0; i < N; i++)
  75.     {
  76.         for (int j = 0; j < M; j++)
  77.         {
  78.             cin >> arr[i][j];
  79.         }
  80.     }
  81.  
  82.     /*for (int i = 0; i < N; i++)
  83.     {
  84.         for (int j = 0; j < M; j++)
  85.         {
  86.             cout << arr[i][j] << " ";
  87.         }
  88.         cout << endl;
  89.     }*/
  90.     int rad;
  91.     cin >> rad;
  92.     cout <<"max = "<< mx(arr, N, M) << endl;
  93.     cout << "Neg_Q = " << neg_Q(arr, N, M) << endl;
  94.     cout << "R = " << R(rad) << endl;
  95.  
  96.     for (int i = 0; i < N; i++)
  97.     {
  98.         delete[] arr[i];
  99.     }
  100.  
  101.     delete[] arr;
  102.  
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement