当前位置:   article > 正文

寒假9-蓝桥杯训练

寒假9-蓝桥杯训练

//轨道炮

  1. #include<iostream>
  2. using namespace std;
  3. #include<algorithm>
  4. int logs[100010];
  5. int main()
  6. {
  7. int n;
  8. cin >> n;
  9. for (int i = 1;i <= n;i++)
  10. {
  11. cin >> logs[i];
  12. }
  13. sort(logs + 1, logs + n + 1);
  14. int ans = 1000000000;
  15. for (int i = 2;i <= n;i++)
  16. {
  17. if (logs[i] - logs[i - 1] < ans)ans = logs[i] - logs[i - 1];
  18. }
  19. int flag = 0;
  20. int res = 1;
  21. while (flag==0)
  22. {
  23. res = 1;
  24. for (int i = 2;i <= n;i++)
  25. {
  26. if ((logs[i] - logs[i - 1]) % ans == 0)
  27. {
  28. res += ((logs[i] - logs[i - 1]) / ans);
  29. }
  30. else
  31. {
  32. ans--;
  33. break;
  34. }
  35. }
  36. flag = 1;
  37. }
  38. cout << res << endl;
  39. return 0;
  40. }

 

  1. #include<iostream>
  2. using namespace std;
  3. #include<string>
  4. int arr[30];
  5. int main()
  6. {
  7. string str;
  8. cin >> str;
  9. for (int i = 0;i < str.length();i++)
  10. {
  11. arr[int(str[i]) - 96]+=1;
  12. }
  13. int ans1=0;
  14. int ans2;
  15. for (int i = 1;i <= 26;i++)
  16. {
  17. if (arr[i] > ans1)
  18. {
  19. ans2 = i;
  20. ans1 = arr[i];
  21. }
  22. }
  23. //cout << arr[15] << endl;
  24. cout << char(ans2 + 96) << endl << ans1 << endl;
  25. return 0;
  26. }

//怒砍20分

  1. #include<iostream>
  2. using namespace std;
  3. char ch[30][30];
  4. char chs[30][30];
  5. int dx[] = { -1,1,0,0 };
  6. int dy[] = { 0,0,-1,1 };
  7. int n, m;
  8. void dfs(int x, int y)
  9. {
  10. chs[x][y] = '1';
  11. ch[x][y] = '0';
  12. for (int i = 0;i < 4;i++)
  13. {
  14. if (x + dx[i] >= 1 && y + dy[i] >= 1&& x + dx[i]<=n&& y + dy[i]<=m)
  15. {
  16. if (ch[x + dx[i]][y + dy[i]] == '1')
  17. {
  18. dfs(x + dx[i], y + dy[i]);
  19. }
  20. }
  21. }
  22. }
  23. int daan()
  24. {
  25. int ans1 = 0;
  26. int ans2 = 0;
  27. for (int i = 1;i <= n;i++)
  28. {
  29. for (int j = 1;j <= m;j++)
  30. {
  31. if (chs[i][j] == '1')
  32. {
  33. if (i == 1 && j == 1)ans1++;
  34. else if (i == 1)
  35. {
  36. if (chs[i][j - 1] == '0')ans1++;
  37. }
  38. else if (j == 1)
  39. {
  40. if (chs[i - 1][j] == '0')ans1++;
  41. }
  42. else if (chs[i - 1][j] == '0' && chs[i][j - 1] == '0')ans1++;
  43. }
  44. }
  45. }
  46. for (int i = 1;i < n;i++)
  47. {
  48. if (chs[i + 1][m] == '0'&&chs[i][m]=='1')ans2++;
  49. }
  50. for (int i = 1;i < m;i++)
  51. {
  52. if (chs[n][i+1] == '0' && chs[n][i] == '1')ans2++;
  53. }
  54. if (chs[n][m] == '1')ans2++;
  55. //cout << "ans1=" << ans1 << " " << "ans2=" << ans2 << endl;
  56. return max(ans1, ans2);
  57. }
  58. int main()
  59. {
  60. int ans = 0;
  61. cin >> n >> m;
  62. for (int i = 1;i <= n;i++)
  63. {
  64. for (int j = 1;j <= m;j++)
  65. {
  66. cin >> ch[i][j];
  67. }
  68. }
  69. for (int i = 1;i <= n;i++)
  70. {
  71. for (int j = 1;j <= m;j++)
  72. {
  73. if (ch[i][j]=='1')
  74. {
  75. for (int z = 1;z <= n;z++)
  76. {
  77. for (int w = 1;w <= m;w++)
  78. {
  79. chs[z][w] = '0';
  80. }
  81. }
  82. dfs(i, j);
  83. /*for (int z = 1;z <= n;z++)
  84. {
  85. for (int w = 1;w <= m;w++)
  86. {
  87. cout << chs[z][w];
  88. }
  89. cout << endl;
  90. }*/
  91. ans += daan();
  92. }
  93. }
  94. }
  95. cout << ans << endl;
  96. return 0;
  97. }

 

  1. #include<iostream>
  2. using namespace std;
  3. #include<string>
  4. int main()
  5. {
  6. string str;
  7. cin >> str;
  8. int l = str.length();
  9. int ans = 0;
  10. for (int i = 0;i < l;i++)
  11. {
  12. ans += (int(str[i] - 48));
  13. }
  14. int flag = ans;
  15. while ((ans / 10) != 0)
  16. {
  17. flag = 0;
  18. while (ans)
  19. {
  20. flag += (ans % 10);
  21. ans /= 10;
  22. }
  23. ans = flag;
  24. }
  25. cout << flag << endl;
  26. return 0;
  27. }

  1. #include<iostream>
  2. using namespace std;
  3. bool use[1000010];
  4. int main()
  5. {
  6. int n, m;
  7. cin >> n >> m;
  8. int maxx = max(n, m);
  9. int minn = min(n, m);
  10. int ans = minn-1;
  11. for (int i = 1;i <= n*m;i++)
  12. {
  13. if (i < minn)
  14. {
  15. use[i] = true;
  16. ans = i;
  17. }
  18. else
  19. {
  20. if (i % minn == 0 || i % maxx == 0)use[i] = false;
  21. else
  22. {
  23. if (i > maxx)
  24. {
  25. if (use[i - minn] == true && use[i - maxx] == true)
  26. {
  27. use[i] = true;
  28. ans = i;
  29. }
  30. }
  31. else if(use[i-minn])
  32. {
  33. use[i] = true;
  34. ans = i;
  35. }
  36. }
  37. }
  38. }
  39. cout << ans << endl;
  40. return 0;
  41. }

 

  1. #include<iostream>
  2. using namespace std;
  3. int n, m;
  4. int sum = 0;
  5. bool use[15][15];
  6. int arr[15][15];
  7. int ans = 10000;
  8. int dx[] = { 0 ,0,-1,1 };
  9. int dy[] = { -1,1,0,0 };
  10. void dfs(int x,int y,int num, int d)
  11. {
  12. //cout << num <<" "<< x<<" "<<y <<" "<< ans<< endl;
  13. if (num > sum)return;
  14. else if (num == sum)
  15. {
  16. if (d < ans)ans = d ;
  17. return;
  18. }
  19. else if (d >= ans)return;
  20. else
  21. {
  22. use[x][y] = true;
  23. for (int i = 0;i < 4;i++)
  24. {
  25. if (x + dx[i] > 0 && x + dx[i] <= n && y + dy[i] > 0 && y + dy[i] <= m && use[x + dx[i]][y + dy[i]] == false)
  26. {
  27. dfs(x + dx[i], y + dy[i], num + arr[x+dx[i]][y+dy[i]], d + 1);
  28. }
  29. }
  30. use[x][y] = false;
  31. }
  32. return;
  33. }
  34. int main()
  35. {//43
  36. cin >> m >> n;
  37. for (int i = 1;i <= n;i++)
  38. {
  39. for (int j = 1;j <= m;j++)
  40. {
  41. cin >> arr[i][j];
  42. sum += arr[i][j];
  43. }
  44. }
  45. if (sum % 2 != 0)
  46. {
  47. cout << 0 << endl;
  48. }
  49. else
  50. {
  51. sum /= 2;
  52. dfs(1, 1, arr[1][1], 1);
  53. if (ans == 10000)
  54. {
  55. cout << 0 << endl;
  56. }
  57. else
  58. {
  59. cout << ans << endl;
  60. }
  61. }
  62. return 0;
  63. }

  1. #include<iostream>
  2. using namespace std;
  3. #include<vector>
  4. int n;
  5. int ans = 0;
  6. int arr[10];
  7. bool use[10];
  8. void f()
  9. {
  10. //cout << 1 << endl;
  11. for (int i = 1;i <= 7;i++)
  12. {
  13. int flag1 = 1;
  14. int num1 = 0;
  15. while (flag1!=i+1)///1-5 1 12 123
  16. {
  17. num1 *= 10;
  18. num1 += arr[flag1];
  19. flag1++;
  20. }
  21. if (num1 >= n)break;
  22. for (int j = i + 1;j <= 8;j++)
  23. {
  24. int num2 = 0;
  25. int flag2 = i+1;
  26. while (flag2!=j+1)
  27. {
  28. num2 *= 10;
  29. num2 += arr[flag2];
  30. flag2++;
  31. }
  32. int num3 = 0;
  33. int flag3 = j+1;
  34. while (flag3 != 10)
  35. {
  36. num3 *= 10;
  37. num3 += arr[flag3];
  38. flag3++;
  39. }
  40. long long n1 = n * num3;
  41. long long n2 = num1 * num3 + num2;
  42. if (n1 == n2)ans++;
  43. }
  44. }
  45. }
  46. void dfs(int u)
  47. {
  48. //cout << 2 << endl;
  49. if (u == 10)
  50. {
  51. f();
  52. return;
  53. }
  54. for (int i = 1;i <= 9;i++)
  55. {
  56. if (!use[i])
  57. {
  58. arr[u] = i;
  59. use[i] = true;
  60. dfs(u + 1);
  61. use[i] = false;
  62. }
  63. }
  64. }
  65. int main()
  66. {
  67. cin >> n;
  68. dfs(1);
  69. cout << ans << endl;
  70. return 0;
  71. }
  72. //#include<iostream>
  73. //#include <algorithm>
  74. //using namespace std;
  75. //int arr[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  76. //int get_num_helper(int a, int b)
  77. //{
  78. // int tmp = 0;
  79. // while (a <= b)
  80. // {
  81. // tmp *= 10;
  82. // tmp += arr[a];
  83. // a++;
  84. // }
  85. // return tmp;
  86. //}
  87. //void get_num(int i, int j, int& a, int& b, int& c)
  88. //{
  89. // a = get_num_helper(0, i);
  90. // b = get_num_helper(i + 1, j);
  91. // c = get_num_helper(j + 1, 8);
  92. //}
  93. //int main()
  94. //{
  95. // int n;
  96. // int ans = 0;
  97. // cin >> n;
  98. // // 1.给出1~9的所有排列9!
  99. // do {
  100. // // 2.对于每个排列进行划分:划分为整数a,分母b,分子c
  101. // int a, b, c;
  102. // for (int i = 0; i < 8; i++)
  103. // {
  104. // for (int j = i + 1; j < 9; j++)
  105. // {
  106. // get_num(i, j, a, b, c);
  107. // if (a == 0 || b == 0 || c == 0) continue;
  108. // // 3.检验划分后的结果是否等于给定数字n
  109. // if (b % c == 0 && a + (b / c) == n) ans++;
  110. // }
  111. // }
  112. //
  113. // } while (next_permutation(arr, arr + 9));
  114. //
  115. // cout << ans << endl;
  116. //
  117. // return 0;
  118. //}

 

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int a, b, c;
  6. cin >> a >> b >> c;
  7. int ans = a * b * c;
  8. for (int i = a * b * c;i >= 1;i--)
  9. {
  10. if ( i % a == 0 && i % b == 0 && i % c == 0)
  11. {
  12. ans = i;
  13. }
  14. }
  15. cout << ans << endl;
  16. return 0;
  17. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/104149
推荐阅读
相关标签
  

闽ICP备14008679号