#include<iostream> #include<queue> #include<algorithm> #include<vector> usingnamespace std; int n, m, start; constint maxn = 40; string maze[maxn]; int steps[maxn * maxn], vis[maxn * maxn]; int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; intvalid(int x, int y){ return x >= 0 && x < n && y >= 0 && y < m && maze[x][y] != '*'; } vector<int> v; voidbfs(){ queue<int> q; q.push(start); vis[start] = 1; steps[start] = 0; while (!q.empty()) { int cur = q.front(); int x = cur / m, y = cur % m; q.pop(); if (maze[x][y] == 'e') continue; for (int i = 0; i < 4; i++) { int nx = x + dir[i][0], ny = y + dir[i][1]; int next = nx * m + ny; if (valid(nx, ny) && !vis[next]) { vis[next] = 1; q.push(next); if (maze[nx][ny] == 'e') { v.push_back(next); } steps[next] = steps[cur] + 1; } } } }
intmain(){ ios::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) cin >> maze[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (maze[i][j] == 'k') { start = i * m + j; } } } v.clear(); bfs(); int _min = 0x3f3f3f3f; for (int i = 0; i < v.size(); i++) { _min = min(steps[v[i]], _min); } if (v.size() == 0) cout << "-1\n"; else cout <<v.size() << " " << _min << endl; return0; }
doublef(int m, int n){ double ans = 1; for (int i = 1; i <= n; i++) { ans = ans * m / i; m--; } return ans; }
double _pow(double n, int k) { double ans = 1; while (k--) { ans *= n; } return ans; } intmain(){ ios::sync_with_stdio(false); double n, m; cin >> m >> n; printf("%.4f\n", f(m, n) * _pow(0.8, n) * _pow(0.2, m - n)); return0; }
#include<iostream> #include<cstdio> #include<cstring> #include<string> usingnamespace std; constint maxn = 1e5 + 10; int sum[maxn], a[maxn]; int n, q, l, r; intlowbit(int x){ return x & (-x); } voidupdate(int index, int val){ for (int i = index; i > 0; i -= lowbit(i)) sum[i] += val; } intask(int index){ int ans = a[index]; for (int i = index; i <= n; i += lowbit(i)) ans += sum[i]; return ans; } intmain(){ ios::sync_with_stdio(false); cin >> n >> q; while (q--) { cin >> l >> r; update(r, 1); update(l - 1, -1); } for (int i = 1; i <= n; i++) { cout << ask(i) << " "; } return0; }