[关闭]
@Dmaxiya 2018-08-17T02:26:03.000000Z 字数 4643 阅读 875

Codeforces Round #386 (Div. 2)

Codeforces


Contests 链接:Codeforces Round #386 (Div. 2)
过题数:4
排名:890/12568

A. Compote

题意

想做一个果盘,要做一个果盘需要的柠檬、苹果、梨的比例为 ,现在他有 个柠檬、 个苹果和 个梨,每个水果都不能再分割,问他要做果盘,能用到的最多的柠檬+苹果+梨的个数是多少?

输入

输入有三行,每行包含一个整数,分别为

输出

输出答案,如果一个水果都不能用上,就输出

样例

输入 输出
2
5
7
7
4
7
13
21
2
3
2
0

题解

按比例取最少的那份,将最小的份数乘

过题代码

  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 a, b, c;
  21. int main() {
  22. #ifdef LOCAL
  23. freopen("test.txt", "r", stdin);
  24. // freopen("out.txt", "w", stdout);
  25. #endif // LOCAL
  26. ios::sync_with_stdio(false);
  27. while(scanf("%d%d%d", &a, &b, &c) != EOF) {
  28. b /= 2;
  29. c /= 4;
  30. int ans = min(a, min(b, c));
  31. printf("%d\n", ans * 7);
  32. }
  33. return 0;
  34. }

B. Decoding

题意

定义字符串的“中位字符”,如果字符串的长度为奇数,那么字符串的中位字符就是正中间的字符,如果字符串的长度为偶数,那么字符串的中位字符就是中间两个字符中,右边的那个字符;
正在对一些字符串进行编码,编码的方式是先选择一个字符串的中位字符,然后删掉这个字符,继续重复以上操作,直到字符串为空。
现在给定一个长度为 的编码字符串,输出解码后的字符串。

输入

第一行为一个整数 ,第二行为一个长度为 的字符串,字符串只包含小写字符。

输出

输出 编码的那个字符串。

样例

输入 输出
5
logva
volga
2
no
no
4
abba
baba

题解

找规律可以发现,如果字符串的长度为奇数,则除了第一个字符在中间位置,其他字符的还原顺序为“左”,如果字符串的长度为偶数,除了第一个字符在中间两个里靠左的那个位置,其他字符的还原顺序为“右”。

过题代码

  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 = 2000 + 100;
  21. int n;
  22. char str[maxn], ans[maxn];
  23. int main() {
  24. #ifdef LOCAL
  25. freopen("test.txt", "r", stdin);
  26. // freopen("out.txt", "w", stdout);
  27. #endif // LOCAL
  28. ios::sync_with_stdio(false);
  29. while(scanf("%d", &n) != EOF) {
  30. memset(ans, 0, sizeof(ans));
  31. scanf("%s", str + 1);
  32. if(n % 2 == 0) {
  33. int l = n / 2;
  34. int r = l + 1;
  35. for(int i = 1; str[i]; ++i) {
  36. if(i % 2 == 0) {
  37. ans[r++] = str[i];
  38. } else {
  39. ans[l--] = str[i];
  40. }
  41. }
  42. } else {
  43. int r = (n + 1) / 2;
  44. int l = r - 1;
  45. for(int i = 1; str[i]; ++i) {
  46. if(i % 2 == 0) {
  47. ans[l--] = str[i];
  48. } else {
  49. ans[r++] = str[i];
  50. }
  51. }
  52. }
  53. ans[n + 1] = '\0';
  54. printf("%s\n", ans + 1);
  55. }
  56. return 0;
  57. }

C. Tram

题意

一辆电车在 之间以 的速度行驶,一旦到达某一个端点,立即掉头回去。
当前在 ,他想要去 ,他步行的速度是 ,且已知此时电车的位置 和电车的行驶方向,他可以在任何时间任何位置上车(不必在整数位置),且他上下车的时间可以忽略不计,问他最快要多久才能到达 点。

输入

第一行包含三个整数 ,第二行包含两个整数 ,第三行包含两个整数 表示电车正在往 的方向行驶, 表示电车正在往 的方向行驶。

输出

输出 要从 到达 的最短时间。

样例

输入 输出
4 2 4
3 4
1 1
8
5 4 0
1 2
3 1
7

题解

如果 想通过电车到达 ,不论 往哪个方向走,他到达 的时间都是相等的,所以如果他想要上车,直接在原地等即可。所以可以用他走路到达 的时间与电车到达 的时间做比较,取较小的那个。计算电车到达的时间直接按题意一米一米地模拟即可。

过题代码

  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 = 20;
  21. int s, x1, x2;
  22. int t1, t2, p, d;
  23. int to[maxn];
  24. bool small(int a, int b, int c) {
  25. return a <= b && b <= c;
  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("%d%d%d", &s, &x1, &x2) != EOF) {
  34. scanf("%d%d%d%d", &t1, &t2, &p, &d);
  35. int ans = abs(x1 - x2) * t2;
  36. bool flag = false;
  37. int t = 0;
  38. while(true) {
  39. if(p == x1) {
  40. flag = true;
  41. }
  42. if(p == x2 && flag) {
  43. break;
  44. }
  45. ++t;
  46. p += d;
  47. if(p == 0) {
  48. d = 1;
  49. } else if(p == s) {
  50. d = -1;
  51. }
  52. }
  53. printf("%d\n", min(ans, t * t1));
  54. }
  55. return 0;
  56. }

D. Green and Black Tea

题意

个字符,其中有 个字符为 'G', 个字符为 'B',要求构造一个字符串,使这个字符串连续相同的字符个数不超过

输入

输入包含四个整数 ,数据保证

输出

如果无法构造出这个字符串,则输出 "NO",否则输出满足条件的字符串,如果有多个解,输出任意一个即可。

样例

输入 输出
5 1 3 2 GBGBG
7 2 2 5 BBGBGBB
4 3 4 0 NO

题解

假设大的那个数字为 ,小的那个数字为 (如果 ,只要交换一下就行了),然后将 拆分成 块,这样可以保证连续的 对应的字符数最少,所以可以通过比较 的大小,如果这个值大于 ,则直接输出 “NO”,否则就将 分成 块,每连续 对应的字符,就插入一个 对应的字符,每经过这样一轮,就更新 的值,将它们减去自己对应的已经确定的字符数量,直到最后。

过题代码

  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, k, a, b;
  21. int main() {
  22. #ifdef LOCAL
  23. freopen("test.txt", "r", stdin);
  24. // freopen("out.txt", "w", stdout);
  25. #endif // LOCAL
  26. ios::sync_with_stdio(false);
  27. while(scanf("%d%d%d%d", &n, &k, &a, &b) != EOF) {
  28. char ch1 = 'G';
  29. char ch2 = 'B';
  30. if(a > b) {
  31. swap(a, b);
  32. swap(ch1, ch2);
  33. }
  34. if((b + a) / (a + 1) > k) {
  35. printf("NO\n");
  36. continue;
  37. }
  38. k = (b + a) / (a + 1);
  39. int cnt = k;
  40. for(int i = 0; i < n; ++i) {
  41. if(cnt == 0) {
  42. b -= k;
  43. --a;
  44. k = (b + a) / (a + 1);
  45. cnt = k;
  46. putchar(ch1);
  47. continue;
  48. }
  49. --cnt;
  50. putchar(ch2);
  51. }
  52. putchar('\n');
  53. }
  54. return 0;
  55. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注