A

  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. double a, b, c, d;
  5. double f(double x) {
  6. return a * x * x * x + b * x * x + c * x + d;
  7. }
  8. /*二分逼近*/
  9. double find(double a, double b) {
  10. if (b - a < 0.0001) return a;
  11. double mid = (a + b) / 2;
  12. if (f(a) * f(mid) > 0) return find(mid, b);
  13. else find(a, mid);
  14. }
  15. int main() {
  16. double x;
  17. cin >> a >> b >> c >> d;
  18. for (double i = -100; i <= 100; i++) {
  19. if (f(i) == 0) cout << fixed << setprecision(2) << i << ' ';
  20. else if (f(i) * f(i + 1) < 0) cout << fixed << setprecision(2) << find(i, i + 1) << ' ';
  21. }
  22. return 0;
  23. }

C++(看看有没有更省时的解法)

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5. int t, n;
  6. cin >> n;
  7. t = n;
  8. int round = 1;
  9. int sum = 1;
  10. while (t - sum > 0) {
  11. round++;
  12. sum += round;
  13. }
  14. int remain = round - abs(t - sum);
  15. if (round % 2) {
  16. cout << round - remain + 1 << "/" << remain;
  17. }
  18. else {
  19. cout << remain<< "/" << round - remain + 1;
  20. }
  21. return 0;
  22. }

E

  1. #include <iostream>
  2. using namespace std;
  3. bool yes_indeed(int a, int b, int c) {
  4. int v[10] = { 0 };
  5. while (a) {
  6. v[a % 10] = 1;
  7. a /= 10;
  8. }
  9. while (b) {
  10. v[b % 10] = 1;
  11. b /= 10;
  12. }
  13. while (c) {
  14. v[c % 10] = 1;
  15. c /= 10;
  16. }
  17. for (int i = 1; i <= 9; i++) {
  18. if (v[i] == 0) return 0;
  19. }
  20. return 1;
  21. }
  22. int main() {
  23. int a, b, c;
  24. for (int a = 123; a <= 329; a++) {
  25. b = 2 * a;
  26. c = 3 * a;
  27. if (yes_indeed(a, b, c)) cout << a << ' ' << b << ' ' << c << endl;
  28. }
  29. return 0;
  30. }

F(来自洛谷,我自己做的超时GG了)

  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. typedef long long ll;
  5. int m, n, ans, flag;
  6. ll gcd(ll a, ll b) {
  7. return b == 0 ? a : gcd(b, a % b);
  8. }
  9. int main()
  10. {
  11. cin >> n >> m;
  12. for (int i = 1; i <= sqrt(1ll * m * n); i++)
  13. {
  14. if ((1ll * n * m) % i == 0 && gcd(i, (1ll * n * m) / i) == n)
  15. {
  16. ans++;
  17. if (1ll * i * i == 1ll * n * m) flag = 1; //两个数相同的情况
  18. }
  19. }
  20. cout << ans * 2 - flag;
  21. return 0;
  22. }

G - 连续自然数和(暴力出奇迹,看看怎么用前缀解题)

  1. #include<iostream>
  2. using namespace std;
  3. int n, sum, j;
  4. int main()
  5. {
  6. cin >> n;
  7. for (int i = 1; i <= n / 2; i++)
  8. {
  9. sum = 0;
  10. for (j = i; j < n; j++)
  11. {
  12. sum += j;
  13. if (sum >= n)break;
  14. }
  15. if (sum == n)cout << i << ' ' << j << endl;
  16. }
  17. return 0;
  18. }

H - 约瑟夫

https://blog.csdn.net/u012135009/article/details/99443183