[关闭]
@Dmaxiya 2018-08-17T10:28:59.000000Z 字数 5519 阅读 1013

Educational Codeforces Round 35

Codeforces


Contests 链接:Educational Codeforces Round 35
过题数:5
排名:116/9081

A. Nearest Minimums

题意

给定一个长度为 的序列,找到所有数字 中的最小值,找到所有等于最小值的两个值中,距离最近的两个数字,输出这个距离。数据保证至少有两个最小值。

数据范围

题解

按照题意模拟一遍。

过题代码

  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 Min;
  23. int num[maxn];
  24. int main() {
  25. #ifdef LOCAL
  26. freopen("test.txt", "r", stdin);
  27. // freopen("out.txt", "w", stdout);
  28. #endif // LOCAL
  29. ios::sync_with_stdio(false);
  30. while(scanf("%d", &n) != EOF) {
  31. Min = INT_MAX;
  32. for(int i = 0; i < n; ++i) {
  33. scanf("%d", &num[i]);
  34. Min = min(Min, num[i]);
  35. }
  36. int dis = INT_MAX;
  37. int last = -200000;
  38. for(int i = 0; i < n; ++i) {
  39. if(num[i] == Min) {
  40. dis = min(dis, i - last);
  41. last = i;
  42. }
  43. }
  44. printf("%d\n", dis);
  45. }
  46. return 0;
  47. }

B. Two Cakes

题意

有两块蛋糕,分别被切成 片与 片,要放到 个盘子里,使得每个盘子里只能有一种蛋糕,每片蛋糕至少被放在一个盘子里,要让所有盘子中的蛋糕片数的最小值最大,输出这个最大值

数据范围

题解

因为要保证每片蛋糕都被放在一个盘子里,所以让 作为片数小的那个,从 遍历最小值,每次判断该最小值是否成立,都先放 片蛋糕,再放 片蛋糕。

过题代码

  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, a, b;
  21. bool judge(int least, int aa, int bb) {
  22. int i;
  23. for(i = 0; i < n; ++i) {
  24. if(aa >= least) {
  25. aa -= least;
  26. } else if(bb >= least) {
  27. bb -= least;
  28. } else {
  29. break;
  30. }
  31. }
  32. return i == n;
  33. }
  34. int main() {
  35. #ifdef LOCAL
  36. freopen("test.txt", "r", stdin);
  37. // freopen("out.txt", "w", stdout);
  38. #endif // LOCAL
  39. ios::sync_with_stdio(false);
  40. while(scanf("%d%d%d", &n, &a, &b) != EOF) {
  41. int ans = 0;
  42. if(a > b) {
  43. swap(a, b);
  44. }
  45. for(int i = a; i >= 0; --i) {
  46. if(judge(i, a, b)) {
  47. ans = i;
  48. break;
  49. }
  50. }
  51. printf("%d\n", ans);
  52. }
  53. return 0;
  54. }

C. Three Garlands

题意

有三种霓虹灯,第 种霓虹灯每 秒亮一次,问,如果给定 ,能否找到三个打开这三种灯的时间点,使得最后一盏灯被打开后,每一秒都至少有一盏灯在发亮。

数据范围

题解

因为有三盏灯要轮流发亮,所以如果三盏灯的间隔时间 都大于 ,则必然找不到任何的方式使得每一秒都至少有一盏灯在发亮,对于不大于 的情况,暴力枚举判断即可。

过题代码

  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 = 50;
  21. int k1, k2, k3;
  22. bool flag;
  23. bool lit[maxn];
  24. bool judge(int a, int b, int c) {
  25. int aa = a;
  26. int bb = b;
  27. int cc = c;
  28. memset(lit, 0, sizeof(lit));
  29. while(aa < maxn) {
  30. lit[aa] = true;
  31. aa += k1;
  32. }
  33. while(bb < maxn) {
  34. lit[bb] = true;
  35. bb += k2;
  36. }
  37. while(cc < maxn) {
  38. lit[cc] = true;
  39. cc += k3;
  40. }
  41. for(int i = max(a, max(b, c)); i < maxn; ++i) {
  42. if(!lit[i]) {
  43. return false;
  44. }
  45. }
  46. return true;
  47. }
  48. int main() {
  49. #ifdef LOCAL
  50. freopen("test.txt", "r", stdin);
  51. // freopen("out.txt", "w", stdout);
  52. #endif // LOCAL
  53. ios::sync_with_stdio(false);
  54. while(scanf("%d%d%d", &k1, &k2, &k3) != EOF) {
  55. if(k1 >= 4 && k2 >= 4 && k3 >= 4) {
  56. printf("NO\n");
  57. continue;
  58. }
  59. flag = false;
  60. for(int i = 1; i <= 5; ++i) {
  61. for(int j = 1; j <= 5; ++j) {
  62. for(int k = 1; k <= 5; ++k) {
  63. if(judge(i, j, k)) {
  64. flag = true;
  65. break;
  66. }
  67. }
  68. if(flag) {
  69. break;
  70. }
  71. }
  72. if(flag) {
  73. break;
  74. }
  75. }
  76. if(flag) {
  77. printf("YES\n");
  78. } else {
  79. printf("NO\n");
  80. }
  81. }
  82. return 0;
  83. }

D. Inversion Counting

题意

给定一个长度为 的全排列 ,有 次操作,每次操作给定区间 ,将序列从 反转,求每次操作后,序列逆序对的奇偶性。

数据范围

题解

改变任意两个数字的的位置,只看这两个数字的话,整体的逆序对奇偶性改变,将 区间上的所有数字反转,则逆序对改变的次数为 ,其中 为反转长度,即

过题代码

  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;
  21. int n, flag, m, l, r;
  22. int num[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. flag = 0;
  31. for(int i = 0; i < n; ++i) {
  32. scanf("%d", &num[i]);
  33. for(int j = 0; j < i; ++j) {
  34. if(num[j] > num[i]) {
  35. ++flag;
  36. }
  37. }
  38. }
  39. flag %= 2;
  40. scanf("%d", &m);
  41. for(int i = 0; i < m; ++i) {
  42. scanf("%d%d", &l, &r);
  43. LL tmp = r - l + 1;
  44. if((tmp - 1) * tmp / 2 % 2 == 1) {
  45. flag = 1 - flag;
  46. }
  47. if(!flag) {
  48. printf("even\n");
  49. } else {
  50. printf("odd\n");
  51. }
  52. }
  53. }
  54. return 0;
  55. }

E. Stack Sorting

题意

如果一个序列,可以通过进栈出栈操作达到非递减的状态,那么这个序列就是“可栈排序”的序列。现在有一个长度为 的排列,给出前 个数字 ,如果能够在这 个数字后将这个排列补全,使这个排列成为一个“可栈排序”序列,则该问题有解,输出字典序最大的那个解,否则输出

数据范围

题解

先对前 个数字用“栈排序”跑一遍,在栈内则存了一个不可“栈排序”的序列,这个序列一定由多个连续的递减序列拼成,从后往前扫一遍这个栈,每当碰到一个数字,就将小于这个数字的,没有出现过的数字添加按从大到小添加到原序列尾部。

过题代码

  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 = 200000 + 100;
  21. int n, k, cnt, Index;
  22. bool vis[maxn];
  23. int num[maxn];
  24. int sta[maxn];
  25. int main() {
  26. #ifdef LOCAL
  27. freopen("test.txt", "r", stdin);
  28. // freopen("out.txt", "w", stdout);
  29. #endif // LOCAL
  30. ios::sync_with_stdio(false);
  31. while(scanf("%d%d", &n, &k) != EOF) {
  32. cnt = 0;
  33. Index = 1;
  34. memset(vis, 0, sizeof(vis));
  35. for(int i = 0; i < k; ++i) {
  36. scanf("%d", &num[i]);
  37. vis[num[i]] = true;
  38. sta[cnt++] = num[i];
  39. while(cnt != 0 && sta[cnt - 1] == Index) {
  40. ++Index;
  41. --cnt;
  42. }
  43. }
  44. for(int i = cnt - 1; i >= 0; --i) {
  45. int tmp = sta[i] - 1;
  46. while(tmp > 0 && !vis[tmp]) {
  47. num[k++] = tmp;
  48. --tmp;
  49. }
  50. }
  51. int tmp = n;
  52. while(tmp > 0 && !vis[tmp]) {
  53. num[k++] = tmp;
  54. --tmp;
  55. }
  56. cnt = 0;
  57. Index = 1;
  58. for(int i = 0; i < n; ++i) {
  59. sta[cnt++] = num[i];
  60. while(cnt != 0 && sta[cnt - 1] == Index) {
  61. ++Index;
  62. --cnt;
  63. }
  64. }
  65. if(cnt == 0) {
  66. for(int i = 0; i < n; ++i) {
  67. if(i != 0) {
  68. printf(" ");
  69. }
  70. printf("%d", num[i]);
  71. }
  72. printf("\n");
  73. } else {
  74. printf("-1\n");
  75. }
  76. }
  77. return 0;
  78. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注