能看到这个视频真正结局的都是大神!_哔哩哔哩
(゜-゜)つロ 干杯~-bilibili
T7 无穷级数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <cstdio> #include <cstdlib> #include <cmath> #include <iostream>
using namespace std;
int main() { int n; cin >> n; if (n == 1) { cout << "Subtask 1: " << endl; double ans = 0; for (register int i = 2;; i++) { double cur = 1 / (log(i) * i); ans += cur; system("cls"); printf("i = %d:\n%.9f\n", i, ans); } } else { cout << "Subtask 2: " << endl; double ans = 0; for (register int i = 2;; i++) { double cur = 1 / (log(i)); ans += cur; system("cls"); printf("i = %d:\n%.9f\n", i, ans); } } }
|
T9 植物大战僵尸
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <cstdio> #include <cstdlib> #include <cmath> #include <iostream>
using namespace std;
double dp[52][6];
int main() { dp[1][1] = 1; dp[1][2] = 0; dp[1][3] = 0; dp[1][4] = 0; dp[1][5] = 0; for (register int i = 2; i <= 51; i++) for (register int j = 1; j <= 5; j++) if (j == 1) dp[i][j] = dp[i - 1][j] * 0.2 + dp[i - 1][j + 1] * 0.4; else if (j == 5) dp[i][j] = dp[i - 1][j] * 0.2 + dp[i - 1][j - 1] * 0.4; else if (j == 2) dp[i][j] = dp[i - 1][j - 1] * 0.8 + dp[i - 1][j] * 0.2 + dp[i - 1][j + 1] * 0.4; else if (j == 4) dp[i][j] = dp[i - 1][j - 1] * 0.4 + dp[i - 1][j] * 0.2 + dp[i - 1][j + 1] * 0.8; else dp[i][j] = dp[i - 1][j - 1] * 0.4 + dp[i - 1][j] * 0.2 + dp[i - 1][j + 1] * 0.4;
for (register int i = 1; i <= 51; i++) { for (register int j = 1; j <= 5; j++) printf("%.8f ", dp[i][j]); cout << endl; } system("pause"); return 0; }
|
T11-T13 队长数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring>
using namespace std;
bool prime[30000001]; bool dzshu[30000001]; int n;
void init() { prime[0] = prime[1] = true; prime[2] = false; for (int i = 2; i <= n; i++) if (!prime[i]) for (int j = 2; i * j <= n; j++) prime[i * j] = true; }
int main() { cout << "n: " << endl; cin >> n;
init();
for (register int i = 233; i <= n; i++) if (!prime[i]) for (register int j = 1; i * j <= n; j++) dzshu[i * j] = true;
int ans = 0; for (register int i = 1; i <= n - 4; i++) ans += dzshu[i];
cout << "There are " << ans << " DZ numbers less than " << n - 3 << '.' << endl; cout << n - 3 << ": " << dzshu[n - 3] << endl; cout << n - 2 << ": " << dzshu[n - 2] << endl; cout << n - 1 << ": " << dzshu[n - 1] << endl; cout << n << ": " << dzshu[n] << endl;
system("pause"); return 0; }
|
T14-T16 博弈论
甲0 乙1 丙2 丁3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring>
using namespace std;
int dp[30000001]; int n;
int better(int a, int b) { if (a == 0 b == 0) return 0; if (a == 3 b == 3) return 3; if (a == 2 b == 2) return 2; return 1; }
int main() { cout << "n: " << endl; cin >> n;
dp[0] = 3; for (register int i = 1; i <= n; i++) { dp[i] = (dp[i - 1] + 1) % 4; if (i >= 11) dp[i] = better(dp[i], (dp[i - 11] + 1) % 4); if (i >= 114) dp[i] = better(dp[i], (dp[i - 114] + 1) % 4); if (i >= 1145) dp[i] = better(dp[i], (dp[i - 1145] + 1) % 4); if (i >= 11451) dp[i] = better(dp[i], (dp[i - 11451] + 1) % 4); if (i >= 114514) dp[i] = better(dp[i], (dp[i - 114514] + 1) % 4); }
cout << dp[n] << endl; system("pause"); return 0; }
|