[关闭]
@Dmaxiya 2018-08-17T10:34:02.000000Z 字数 2958 阅读 1057

Codeforces Round #414 (Div. 1 + Div. 2)

Codeforces


Contests 链接:Codeforces Round #414 (Div. 1 + Div. 2)
过题数:2
排名:911/6157

A. Bank Robbery

题意

个保险箱,第 个保险箱内有 的钱,一个小偷在位置 ,有两个保安在位置 ,要求小偷不能走到保安的位置,且能够偷到的最多的钱。

数据范围

题解

计算出 ,就是结果。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. const int maxn = 100000 + 100;
  21. int n;
  22. int a, b, c;
  23. int l, r;
  24. LL ans;
  25. int num[maxn];
  26. int main() {
  27. #ifdef LOCAL
  28. freopen("test.txt", "r", stdin);
  29. // freopen("out.txt", "w", stdout);
  30. #endif // LOCAL
  31. ios::sync_with_stdio(false);
  32. while(scanf("%d%d%d", &a, &b, &c) != EOF) {
  33. scanf("%d", &n);
  34. ans = 0;
  35. for(int i = 0; i < n; ++i) {
  36. scanf("%d", &num[i]);
  37. if(num[i] > b && num[i] < c) {
  38. ++ans;
  39. }
  40. }
  41. printf("%I64d\n", ans);
  42. }
  43. return 0;
  44. }

B. Cutting Carrot

题意

将一个高为 的等腰三角形切成面积相等的 段,输出 个数字,表示每次切的位置。

数据范围

题解

推出公式 ,输出结果。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. int n;
  21. double h;
  22. int main() {
  23. #ifdef LOCAL
  24. freopen("test.txt", "r", stdin);
  25. // freopen("out.txt", "w", stdout);
  26. #endif // LOCAL
  27. ios::sync_with_stdio(false);
  28. while(scanf("%d%lf", &n, &h) != EOF) {
  29. for(int i = 1; i < n; ++i) {
  30. if(i != 1) {
  31. printf(" ");
  32. }
  33. printf("%.10f", h * sqrt((double)i / n));
  34. }
  35. printf("\n");
  36. }
  37. return 0;
  38. }

C. Naming Company

题意

两人玩一个游戏, 先开始,两个人各有一个长度为 的字符串,最开始有一个长度为 的只包含 的字符串,两人轮流从自己的字符串中选一个字符替换其中的一个 想让这个结果字符的字典序最小, 想让这个字符的字典序最大,如果两人都采取最优策略,输出所有 字符都被替换之后的字符串。

数据范围

题解

的字符串按从小到大排序, 的字符串从大到小排序,如果 最小的字符小于 最大的字符,就将这个最小的字符替换最前面的问号,如果 最小的字符大于等于 最大的字符,就从后面往前面放,但是仍然要使字典序最小,所以他会先放自己最后要放下的,最大的字符。 就与 相反。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. const int maxn = 3000000 + 100;
  21. int n;
  22. char str1[maxn], str2[maxn];
  23. char ans[maxn];
  24. bool cmp(const char &a, const char &b) {
  25. return a > b;
  26. }
  27. int main() {
  28. #ifdef LOCAL
  29. freopen("test.txt", "r", stdin);
  30. // freopen("out.txt", "w", stdout);
  31. #endif // LOCAL
  32. ios::sync_with_stdio(false);
  33. while(scanf("%s%s", str1, str2) != EOF) {
  34. int n = strlen(str1);
  35. sort(str1, str1 + n);
  36. sort(str2, str2 + n, cmp);
  37. int who = 1;
  38. int cnt = n;
  39. int l = 0;
  40. int r = n - 1;
  41. int l2 = 0, r2 = n / 2;
  42. int l1 = 0, r1 = n - r2;
  43. --r1;
  44. --r2;
  45. memset(ans, 0, sizeof(ans));
  46. while(cnt != 0) {
  47. if(who == 1) {
  48. if(str1[l1] < str2[l2]) {
  49. ans[l++] = str1[l1++];
  50. } else {
  51. ans[r--] = str1[r1--];
  52. }
  53. } else {
  54. if(str2[l2] > str1[l1]) {
  55. ans[l++] = str2[l2++];
  56. } else {
  57. ans[r--] = str2[r2--];
  58. }
  59. }
  60. who = 3 - who;
  61. --cnt;
  62. }
  63. printf("%s\n", ans);
  64. }
  65. return 0;
  66. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注