Selaa lähdekoodia

上传文件至 ''

webturing 5 vuotta sitten
vanhempi
commit
f5938a75f5
5 muutettua tiedostoa jossa 192 lisäystä ja 0 poistoa
  1. 33 0
      D2.cpp
  2. 32 0
      E.cpp
  3. 30 0
      F.cpp
  4. 61 0
      G.cpp
  5. 36 0
      I.cpp

+ 33 - 0
D2.cpp

@@ -0,0 +1,33 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+const int n = 10;
+int a[n];
+bool used[n];
+
+void dfs(int k) {
+    if (k == n) {
+        int x = a[1] * 100 + a[2] * 10 + a[3];
+        int y = a[4] * 100 + a[5] * 10 + a[6];
+        int z = a[7] * 100 + a[8] * 10 + a[9];
+        if (y == 2 * x && z == 3 * x) {
+            cout << x << y << z << endl;
+        }
+        return;
+    }
+    for (int i = 1; i < n; i++) {
+        if (!used[i]) {
+            used[i] = true;
+            a[k] = i;
+            dfs(k + 1);
+            used[i] = false;
+        }
+    }
+}
+
+int main() {
+    dfs(1);
+    return 0;
+}
+ 

+ 32 - 0
E.cpp

@@ -0,0 +1,32 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    for (int n; cin >> n;) {
+        if (n == 0)break;
+        vector<vector<int>> a(n, vector<int>(n, 0));//int a[n][n]={0}
+        vector<vector<bool>> used(n, vector<bool>(n, false));//bool used[n][n]={false;}
+        int x = n - 1, y = n / 2;
+        a[x][y] = 1;
+        used[x][y] = true;
+        for (int k = 2; k <= n * n; k++) {
+            if (!used[(x + 1) % n][(y + 1) % n]) {
+                x = (x + 1) % n;
+                y = (y + 1) % n;
+            } else if (!used[(x - 1 + n) % n][y]) {
+                x = (x - 1 + n) % n;
+            }
+            a[x][y] = k;
+            used[x][y] = true;
+        }
+        for (int i = 0; i < n; i++) {
+            for (int j = 0; j < n; j++) {
+                printf("%2d ", a[i][j]);
+            }
+            cout << endl;
+        }
+    }
+
+    return 0;
+}

+ 30 - 0
F.cpp

@@ -0,0 +1,30 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+struct PPP {
+    string name;
+    int A, B, C;
+
+    bool operator<(const PPP &that) const {
+        if (A - that.A)return A < that.A;
+        if (B - that.B)return B < that.B;
+        if (C - that.C)return C < that.C;
+        return name < that.name;
+
+    }
+};
+
+
+int main() {
+    int n;
+    while (cin >> n) {
+        PPP N[n];
+        for (int i = 0; i < n; i++) {
+            cin >> N[i].name >> N[i].A >> N[i].B >> N[i].C;
+        }
+        PPP *mp = min_element(N, N + n);
+        cout << mp->name << " " << mp->A << " " << mp->B << " " << mp->C << endl;
+    }
+    return 0;
+}

+ 61 - 0
G.cpp

@@ -0,0 +1,61 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+typedef long long LL;
+const int MAXN = 50 + 10;
+int Next[4][2] = {{-1, 0},
+                  {0,  1},
+                  {1,  0},
+                  {0,  -1}};
+char G[MAXN][MAXN];
+int vis[MAXN][MAXN];
+int sx, sy;
+int ex, ey;
+int n, m;
+
+bool BFS() {
+    memset(vis, 0, sizeof(vis));
+    queue<pair<int, int> > que;
+    que.push(make_pair(sx, sy));
+    vis[sx][sy] = 1;
+    while (!que.empty()) {
+        int x = que.front().first;
+        int y = que.front().second;
+        que.pop();
+        if (G[x][y] == 'L')
+            return true;
+        for (int i = 0; i < 4; i++) {
+            int tx = x + Next[i][0];
+            int ty = y + Next[i][1];
+            if (tx < 1 || tx > n || ty < 1 || ty > m)
+                continue;
+            if (vis[tx][ty] == 1 || G[tx][ty] == 'x')
+                continue;
+            que.push(make_pair(tx, ty));
+            vis[tx][ty] = 1;
+        }
+    }
+    return false;
+}
+
+int main() {
+    while (cin >> n >> m) {
+        for (int i = 1; i <= n; i++) {
+            for (int j = 1; j <= m; j++) {
+                cin >> G[i][j];
+                if (G[i][j] == 'S')
+                    sx = i, sy = j;
+                if (G[i][j] == 'L')
+                    ex = i, ey = j;
+            }
+        }
+        if (BFS())
+            cout << "I saved him." << endl;
+        else
+            cout << "Sorry, I can't save him." << endl;
+    }
+
+    return 0;
+}
+ 

+ 36 - 0
I.cpp

@@ -0,0 +1,36 @@
+#include <bits/stdc++.h>
+using namespace std;
+typedef long long LL;
+LL MOD = 1000000007L;
+
+inline bool prime(int n) {
+    if (n == 2)return true;
+    if (n < 2 || n % 2 == 0)return false;
+    for (int i = 3; i <= n / i; i += 2)
+        if (n % i == 0)return false;
+    return true;
+}
+
+inline int log(int n, int base) {
+    if (n < base)return 0;
+    return 1 + log(n / base, base);
+}
+
+int main() {
+    int n;
+    cin >> n;
+    map<int, int> M;
+    M[2] = log(n, 2);
+    for (int i = 3; i <= n; i += 2) {
+        if (prime(i))
+            M[i] = log(n, i);
+    }
+
+    LL ans = 1LL;
+    for (auto m:M) {
+        for (int i = 1; i <= m.second; i++)//如果指数很大,可以用快速幂
+            ans = (ans * m.first) % MOD;
+    }
+    cout << ans << endl;
+    return 0;
+}