Advertisement
dimuster

Олимпиада ИНФ ТМБ МУП

Dec 16th, 2020 (edited)
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. // 1
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int x1, x2, x3, x4, xmx;
  9.     cin >> x1 >> x2 >> x3 >> x4;
  10.  
  11.     xmx = (x1 + x2 + x3 + x4) / 3;
  12.  
  13.     if (x1 == xmx)
  14.         cout << x1 - x2 << " " << x1 - x3 << " " << x1 - x4;
  15.     else if (x2 == xmx)
  16.         cout << x2 - x1 << " " << x2 - x3 << " " << x2 - x4;
  17.     else if (x3 == xmx)
  18.         cout << x3 - x1 << " " << x3 - x2 << " " << x3 - x4;
  19.     else
  20.         cout << x4 - x1 << " " << x4 - x2 << " " << x4 - x3;
  21.  
  22.     return 0;
  23. }
  24.  
  25. // 2
  26.  
  27. #include <iostream>
  28.  
  29. using namespace std;
  30.  
  31. int main() {
  32.     int N, h = 0;
  33.     cin >> N;
  34.     for (int i = 2; i <= N; i += 3) {
  35.         h++;
  36.         N -= i;
  37.     }
  38.     cout << h;
  39.     return 0;
  40. }
  41.  
  42. // 3 O(n+q^2)
  43.  
  44. #include <iostream>
  45.  
  46. using namespace std;
  47.  
  48. int main() {
  49.  
  50.     int n, x, q, m, s = 0;
  51.     cin >> n;
  52.     int a[n + 1];
  53.     for (int i = 1; i <= n; i++) {
  54.         cin >> x;
  55.         a[i] = x;
  56.     }
  57.  
  58.     cin >> q;
  59.  
  60.     for (int i = 1; i <= q; i++) {
  61.         cin >> m;
  62.         for (int j = 1; j <= n; j++) {
  63.             if (m >= a[j]) {
  64.                 s++;
  65.             }
  66.         }
  67.         cout << s;
  68.         s = 0;
  69.     }
  70.  
  71.     return 0;
  72. }
  73.  
  74. // 3 O(n + q)
  75.  
  76. #include <iostream>
  77.  
  78. using namespace std;
  79.  
  80. int main() {
  81.  
  82.     int n, x, q, m, ma = 0;
  83.     cin >> n;
  84.     int a[n + 1];
  85.     for (int i = 1; i <= n; i++) {
  86.         cin >> x;
  87.         a[x]++;
  88.         ma = max(ma, x);
  89.     }
  90.  
  91.     for (int i = 0; i < ma; i++) {
  92.         a[i+1] += a[i];
  93.     }
  94.  
  95.     cin >> q;
  96.     for (int i = 1; i <= q; i++) {
  97.         cin >> m;
  98.         if (m >= ma)
  99.             cout << a[ma] << ' ';
  100.         else
  101.             cout << a[m] << ' ';
  102.     }
  103.  
  104.     return 0;
  105. }
  106.  
  107. //4
  108.  
  109. #include <iostream>
  110.  
  111. using namespace std;
  112.  
  113. int main() {
  114.     int n, f;
  115.     bool flag = false;
  116.  
  117.     cin >> n;
  118.     int a[n + 1];
  119.     for (int i = 1; i <= n; i++) {
  120.         cin >> f;
  121.         a[i] = f;
  122.     }
  123.  
  124.     for (int i = 1; i <= n; i++) {
  125.         if (a[a[a[i]]] == i) {
  126.             flag = true;
  127.             break;
  128.         }
  129.     }
  130.  
  131.     if (flag)
  132.         cout << "YES";
  133.     else
  134.         cout << "NO";
  135.  
  136.     return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement