webturing преди 5 години
родител
ревизия
146a02b176
променени са 5 файла, в които са добавени 129 реда и са изтрити 0 реда
  1. 15 0
      A.cpp
  2. 23 0
      B.cpp
  3. 46 0
      C.cpp
  4. 18 0
      D.cpp
  5. 27 0
      E.cpp

+ 15 - 0
A.cpp

@@ -0,0 +1,15 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    for (string s; cin >> s;) {
+        char max_char = *max_element(s.begin(), s.end());
+        for (char c:s) {
+            cout << c;
+            if (c == max_char)cout << "(max)";
+        }
+        cout << endl;
+    }
+    return 0;
+}

+ 23 - 0
B.cpp

@@ -0,0 +1,23 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+//O(n*log(m))
+int main() {
+    int m, n;
+    cin >> m >> n;
+    vector<int> a(m, 0), b(n, 0);
+    for (auto &i:a)cin >> i;
+    for (auto &i:b)cin >> i;
+    sort(a.begin(), a.end());
+    sort(b.begin(), b.end());
+    if (m < n)swap(a, b);
+    auto best = INT_MAX;
+    for (auto x:a) {
+        auto p = lower_bound(b.begin(), b.end(), x);
+        best = min(best, abs(*p - x));
+        if (best == 0)break;
+    }
+    cout << best << endl;
+    return 0;
+}

+ 46 - 0
C.cpp

@@ -0,0 +1,46 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+int a[21];
+int used[21];
+int n;
+int tot = 0;
+bool flag = false;
+
+void dfs(int k) {
+    if (flag)return;
+    if (k == n) {
+        int sum = 0;
+        for (int i = 0; i < k; i++) {
+            if (used[i])sum += a[i];
+        }
+        if (sum == tot)flag = true;
+        return;
+    }
+    used[k] = false;
+    dfs(k + 1);
+    used[k] = true;
+    dfs(k + 1);
+}
+
+int main() {
+    while (cin >> n) {
+        fill(used, used + n, false);
+        flag = false;
+        tot = 0;
+        for (int i = 0; i < n; i++) {
+            cin >> a[i];
+            tot += a[i];
+        }
+        if (tot % 2 == 0) {
+            tot /= 2;
+            dfs(0);
+        }
+        if (flag)
+            cout << "Of course,I can!" << endl;
+        else
+            cout << "Sorry,I can't!" << endl;
+
+    }
+    return 0;
+}

+ 18 - 0
D.cpp

@@ -0,0 +1,18 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {//n!
+    int a[] = {0, 1, 2, 3, 4, 5, 6, 7};
+    do {
+        bool ok = true;
+        for (int i = 0; i < 8; i++)
+            for (int j = i + 1; j < 8; j++)
+                if (abs(a[i] - a[j]) == j - i)
+                    ok = false;
+        if (ok)
+            cout << a[0] << a[1] << a[2] << a[3] << a[4] << a[5] << a[6] << a[7] << endl;
+    } while (next_permutation(a, a + 8));
+
+    return 0;
+}

+ 27 - 0
E.cpp

@@ -0,0 +1,27 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    vector<int> F(1, 1);
+    for (int i = 2; i <= 9; i++) {
+        F.push_back(F[F.size() - 1] * i);
+    }
+    int T;
+    cin >> T;
+    while (T--) {
+        int n;
+        cin >> n;
+        for (int i = F.size() - 1; i >= 0; i--) {
+            if (F[i] <= n) {
+                n -= F[i];
+            }
+        }
+        if (n == 0) {
+            cout << "Yes" << endl;
+        } else {
+            cout << "No" << endl;
+        }
+    }
+    return 0;
+}