[关闭]
@Dmaxiya 2018-08-17T02:18:08.000000Z 字数 3219 阅读 904

Educational Codeforces Round 38

Codeforces


Contests 链接:Educational Codeforces Round 38
过题数:2
排名:1341/9908

A. Word Correction

题意

给定一个字符串,在字符串中如果出现连续的两个元音字母(‘a', 'e', 'i', 'o', 'u', 'y'),就用第一个元音字母代替这两个元音字母。

输入

输入为一个只包含小写字母的字符串

输出

输出最终字符串。

样例

输入 输出 提示
5
weird
werd
4
word
word 这个字符串中没有连续的两个元音字母。
5
aaeaa
a

题解

按照题意模拟。

过题代码

  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. using namespace std;
  17. #define LL long long
  18. const int maxn = 200;
  19. int n;
  20. char str[maxn], ch[10] = "aeiouy";
  21. set<char> st;
  22. int main() {
  23. #ifdef Dmaxiya
  24. freopen("test.txt", "r", stdin);
  25. #endif // Dmaxiya
  26. for(int i = 0; i < 6; ++i) {
  27. st.insert(ch[i]);
  28. }
  29. while(scanf("%d%s", &n, str) != EOF) {
  30. bool flag = false;
  31. for(int i = 0; i < n; ++i) {
  32. if(st.find(str[i]) != st.end()) {
  33. if(!flag) {
  34. printf("%c", str[i]);
  35. }
  36. flag = true;
  37. } else {
  38. printf("%c", str[i]);
  39. flag = false;
  40. }
  41. }
  42. printf("\n");
  43. }
  44. return 0;
  45. }

B. Run For Your Prize

题意

一个人站在 的地方,另一个人站在 的地方,在这之间有 个奖品,每个奖品的位置分别为 ,且没有任何两个奖品在同一个位置,每个人的移动速度都是 ,如果某个人的位置正好和某个奖品的位置相同,他可以立即捡起这个奖品,问两人合作将所有奖品捡起的最短时间。

输入

第一行为一个整数 ,第二行为 个整数 ,输入按升序给出。

输出

输出两人合作捡起所有奖品需要的最少时间。

样例

输入 输出 提示
3
2 3 9
8 所有奖品都由在 处的人捡起,另一个人不需要移动。
2
2 999995
5 的人捡起第一个奖品, 的人捡起第二个奖品。

题解

枚举所有相邻位置的分割点,两个人捡起所有物品的时间就是 ,取最小值就是答案。

过题代码

  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. using namespace std;
  17. #define LL long long
  18. const int maxn = 100000 + 100;
  19. int n, ans;
  20. int num[maxn];
  21. int main() {
  22. #ifdef Dmaxiya
  23. freopen("test.txt", "r", stdin);
  24. #endif // Dmaxiya
  25. while(scanf("%d", &n) != EOF) {
  26. ans = INT_MAX;
  27. num[0] = 1;
  28. num[n + 1] = 1000000;
  29. for(int i = 1; i <= n; ++i) {
  30. scanf("%d", &num[i]);
  31. }
  32. for(int i = 0; i <= n; ++i) {
  33. ans = min(ans, max(num[i] - 1, 1000000 - num[i + 1]));
  34. }
  35. printf("%d\n", ans);
  36. }
  37. return 0;
  38. }

C. Constructing Tests

题意

给定一个整数 ,要求构造一个 矩阵,使得这个矩阵中,任意一个 的子矩阵中都至少含有一个 ,且矩阵中 的数量的最大值等于

输入

第一行为一个整数 ,接下去有 个整数

输出

对于每个 ,都输出一行两个整数 ,要求 满足题给条件且 ,如果不存在满足条件的答案,输出

样例

输入 输出
3
21
0
1
5 2
1 1
-1

题解

可以发现,要使得 矩阵中的 的数量最多,就要让 的矩阵中每个 的位置都放上一个 ,因此矩阵中最多的 的数量就等于 ,可以对于 内所有的整数,二分 的值使 满足公式的值等于

过题代码

  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. using namespace std;
  17. #define LL long long
  18. int T;
  19. LL x, n, m;
  20. LL judge(LL mid) {
  21. return n * n - (n / mid) * (n / mid);
  22. }
  23. int main() {
  24. #ifdef Dmaxiya
  25. freopen("test.txt", "r", stdin);
  26. #endif // Dmaxiya
  27. while(scanf("%d", &T) != EOF) {
  28. while(T--) {
  29. m = -1;
  30. scanf("%I64d", &x);
  31. LL sq = sqrt(x) + 1;
  32. for(n = sq; n * n <= 4000000000LL; ++n) {
  33. LL low = 1;
  34. LL high = n;
  35. LL mid;
  36. while(high - low > 1) {
  37. mid = (high + low) / 2;
  38. if(judge(mid) >= x) {
  39. high = mid;
  40. } else {
  41. low = mid;
  42. }
  43. }
  44. if(judge(high) == x) {
  45. m = high;
  46. break;
  47. }
  48. }
  49. if(m == -1) {
  50. printf("-1\n");
  51. } else {
  52. printf("%I64d %I64d\n", n, m);
  53. }
  54. }
  55. }
  56. return 0;
  57. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注