Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1
- #include <iostream>
- using namespace std;
- int main() {
- int x1, x2, x3, x4, xmx;
- cin >> x1 >> x2 >> x3 >> x4;
- xmx = (x1 + x2 + x3 + x4) / 3;
- if (x1 == xmx)
- cout << x1 - x2 << " " << x1 - x3 << " " << x1 - x4;
- else if (x2 == xmx)
- cout << x2 - x1 << " " << x2 - x3 << " " << x2 - x4;
- else if (x3 == xmx)
- cout << x3 - x1 << " " << x3 - x2 << " " << x3 - x4;
- else
- cout << x4 - x1 << " " << x4 - x2 << " " << x4 - x3;
- return 0;
- }
- // 2
- #include <iostream>
- using namespace std;
- int main() {
- int N, h = 0;
- cin >> N;
- for (int i = 2; i <= N; i += 3) {
- h++;
- N -= i;
- }
- cout << h;
- return 0;
- }
- // 3 O(n+q^2)
- #include <iostream>
- using namespace std;
- int main() {
- int n, x, q, m, s = 0;
- cin >> n;
- int a[n + 1];
- for (int i = 1; i <= n; i++) {
- cin >> x;
- a[i] = x;
- }
- cin >> q;
- for (int i = 1; i <= q; i++) {
- cin >> m;
- for (int j = 1; j <= n; j++) {
- if (m >= a[j]) {
- s++;
- }
- }
- cout << s;
- s = 0;
- }
- return 0;
- }
- // 3 O(n + q)
- #include <iostream>
- using namespace std;
- int main() {
- int n, x, q, m, ma = 0;
- cin >> n;
- int a[n + 1];
- for (int i = 1; i <= n; i++) {
- cin >> x;
- a[x]++;
- ma = max(ma, x);
- }
- for (int i = 0; i < ma; i++) {
- a[i+1] += a[i];
- }
- cin >> q;
- for (int i = 1; i <= q; i++) {
- cin >> m;
- if (m >= ma)
- cout << a[ma] << ' ';
- else
- cout << a[m] << ' ';
- }
- return 0;
- }
- //4
- #include <iostream>
- using namespace std;
- int main() {
- int n, f;
- bool flag = false;
- cin >> n;
- int a[n + 1];
- for (int i = 1; i <= n; i++) {
- cin >> f;
- a[i] = f;
- }
- for (int i = 1; i <= n; i++) {
- if (a[a[a[i]]] == i) {
- flag = true;
- break;
- }
- }
- if (flag)
- cout << "YES";
- else
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement