Kaynağa Gözat

上传文件至 ''

webturing 5 yıl önce
ebeveyn
işleme
b28a885a70
4 değiştirilmiş dosya ile 174 ekleme ve 0 silme
  1. 42 0
      F.cpp
  2. 73 0
      G.cpp
  3. 32 0
      H.cpp
  4. 27 0
      I.cpp

+ 42 - 0
F.cpp

@@ -0,0 +1,42 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int n, m;
+    while (cin >> n >> m) {
+        vector<string> M(n + 1);
+        for (int i = 0; i < n; i++) cin >> M[i];
+        int t = 0;
+        for (int i = 0; i < n; i++) {
+            for (int j = 0; j < m; j++) {
+                int x, y, sum = 0;
+                if (M[i][j] == '.') {
+                    x = i, y = j;
+                    while (M[x][y] != '#' && x >= 0) {
+                        if (M[x][y] == 'G') sum++;
+                        x--;
+                    }
+                    x = i, y = j;
+                    while (M[x][y] != '#' && x < n) {
+                        if (M[x][y] == 'G') sum++;
+                        x++;
+                    }
+                    x = i, y = j;
+                    while (M[x][y] != '#' && y >= 0) {
+                        if (M[x][y] == 'G') sum++;
+                        y--;
+                    }
+                    x = i, y = j;
+                    while (M[x][y] != '#' && y < m) {
+                        if (M[x][y] == 'G') sum++;
+                        y++;
+                    }
+                    if (sum > t) t = sum;
+                }
+            }
+        }
+        cout << t << endl;
+    }
+    return 0;
+}

+ 73 - 0
G.cpp

@@ -0,0 +1,73 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+int n, m, sx, sy;
+int dir[4][2] = {
+        {1,  0},
+        {-1, 0},
+        {0,  1},
+        {0,  -1}
+};
+char a[50][50];
+int book[50][50];
+int cnt = 0;
+
+int f(int x, int y);
+
+void dfs(int x, int y);
+
+int main() {
+    cin >> n >> m >> sx >> sy;
+    for (int i = 0; i < n; i++) {
+        cin >> a[i];
+    }
+    for (int i = 0; i < n; i++) {
+        for (int j = 0; j < m; j++) {
+            book[i][j] = 0;
+        }
+    }
+    dfs(sx, sy);
+    cout << cnt << endl;
+}
+
+void dfs(int x, int y) {
+    int sum = f(x, y);
+    if (sum > cnt)cnt = sum;
+    if (sum == 35) {
+        cerr << x << " " << y << endl;
+    }
+    for (int k = 0; k < 4; k++) {
+        int tx = x + dir[k][0];
+        int ty = y + dir[k][1];
+        if (tx < 0 || ty < 0 || tx >= n || ty >= m || a[tx][ty] != '.' || book[tx][ty] == 1)continue;
+        book[tx][ty] = 1;
+        dfs(tx, ty);
+        book[tx][ty] = 0;
+    }
+}
+
+int f(int x, int y) {
+    int ret = 0;
+    int i = x, j = y;
+    while (i >= 0 && a[i][j] != '#') {
+        if (a[i][j] == 'G')ret++;
+        i--;
+    }
+    i = x, j = y;
+    while (i < n && a[i][j] != '#') {
+        if (a[i][j] == 'G')ret++;
+        i++;
+    }
+    i = x, j = y;
+    while (j >= 0 && a[i][j] != '#') {
+        if (a[i][j] == 'G')ret++;
+        j--;
+    }
+    i = x;
+    j = y;
+    while (j < m && a[i][j] != '#') {
+        if (a[i][j] == 'G')ret++;
+        j++;
+    }
+    return ret;
+}

+ 32 - 0
H.cpp

@@ -0,0 +1,32 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+int used[10000] = {0};
+int N;
+int a[10000];
+
+void dfs(int k) {
+    if (k == N) {
+        for (int i = 0; i < k; i++)
+            if (used[i]) {
+                cout << a[i];
+            }
+        cout << endl;
+        return;
+    }
+    for (int i = 1; i < N; i++)
+        if (used[i] == 0) {
+            a[k] = i;
+            used[i] = 1;
+            dfs(k + 1);
+            used[i] = 0;
+        }
+}
+
+int main() {
+    cin >> N;
+    N += 1;
+    dfs(1);
+
+    return 0;
+}

+ 27 - 0
I.cpp

@@ -0,0 +1,27 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int f(int k) {
+    int a[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
+    int m = 0;
+    while (k / 10 != 0) {
+        m += a[k % 10];
+        k = k / 10;
+    }
+    m += a[k];
+    return m;
+}
+
+int main() {
+    int n, i, j, q = 0, c;
+    cin >> n;
+    for (i = 0; i <= 1111; i++) {
+        for (j = 0; j <= 1111; j++) {
+            c = i + j;
+            if (f(i) + f(j) + f(c) == n - 4) q++;
+        }
+    }
+    cout << q;
+    return 0;
+}