[关闭]
@Dmaxiya 2018-08-17T10:29:54.000000Z 字数 3215 阅读 1050

Good Bye 2017

Codeforces


Contests 链接:Good Bye 2017
过题数:3
排名:1074/10923

A. New Year and Counting Cards

题意

有一些卡片,每张卡片有正反两面,一面为小写字母,另一面为一位数字,如果对于每个元音字母背面都是一个偶数的话,这些卡片的状态就为真,否则就为假,给出 张卡片,问最坏情况下,最少需要看多少张卡片的背面,才能确定所有卡片的状态,卡片用字符串 表示。

数据范围

题解

统计字符串中奇数与元音字母的个数。

过题代码

  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 = 100;
  21. char str[maxn];
  22. char ch[11] = "aeiou13579";
  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("%s", str) != EOF) {
  30. int ans = 0;
  31. for(int i = 0; str[i]; ++i) {
  32. for(int j = 0; j < 10; ++j) {
  33. if(str[i] == ch[j]) {
  34. ++ans;
  35. }
  36. }
  37. }
  38. printf("%d\n", ans);
  39. }
  40. return 0;
  41. }

B. New Year and Buggy Bot

题意

给机器人一个指令 ,指令中只包含 ,每个数字代表"上下左右"中的一个方向,但是机器人忘了它们分别是如何一一对应的,问存在多少种指令的分配方式,使得机器人在 的矩阵中,能够从 位置移动到 位置,其中 是障碍物,机器人不能通过。

数据范围

题解

用 next_permutation 函数将所有分配方式都在图上模拟跑一遍,存在一次可行,就输出计数加一。

过题代码

  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 = 200;
  21. int n, m, x, y;
  22. char str[maxn];
  23. char G[maxn][maxn];
  24. const int dir[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
  25. int f[10];
  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", &n, &m) != EOF) {
  33. for(int i = 1; i <= n; ++i) {
  34. scanf("%s", G[i] + 1);
  35. G[i][0] = G[i][m + 1] = '#';
  36. for(int j = 1; j <= m; ++j) {
  37. if(G[i][j] == 'S') {
  38. x = i;
  39. y = j;
  40. }
  41. }
  42. }
  43. for(int i = 0; i <= m + 1; ++i) {
  44. G[0][i] = G[n + 1][i] = '#';
  45. }
  46. scanf("%s", str);
  47. for(int i = 0; i < 4; ++i) {
  48. f[i] = i;
  49. }
  50. int ans = 0;
  51. int xx, yy;
  52. do {
  53. xx = x;
  54. yy = y;
  55. for(int i = 0; str[i]; ++i) {
  56. int tmp = str[i] - '0';
  57. xx += dir[f[tmp]][0];
  58. yy += dir[f[tmp]][1];
  59. if(G[xx][yy] == 'E') {
  60. ++ans;
  61. break;
  62. } else if(G[xx][yy] == '#') {
  63. break;
  64. }
  65. }
  66. } while(next_permutation(f, f + 4));
  67. printf("%d\n", ans);
  68. }
  69. return 0;
  70. }

C. New Year and Curling

题意

个半径为 的圆,从 的地方向 竖直下落,碰到之前的圆或者 则停止,输出每次下落后,每个圆停止位置的圆心纵坐标,输出精确到小数点后六位。

数据范围

题解

因为 很小,所以每次下落 判断是否和已经停止的圆相切,如果相切,则计算出纵坐标,否则纵坐标为 ,可以 解决。

过题代码

  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 = 1000 + 100;
  21. struct Node {
  22. LL x;
  23. long double y;
  24. };
  25. int n;
  26. LL r;
  27. Node node[maxn];
  28. long double get_y(LL x, long double y, LL xtmp) {
  29. if(abs(x - xtmp) > 2 * r) {
  30. return r;
  31. }
  32. return sqrt((4 * r * r) - (x - xtmp) * (x - xtmp)) + y;
  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%I64d", &n, &r) != EOF) {
  41. for(int i = 0; i < n; ++i) {
  42. scanf("%I64d", &node[i].x);
  43. long double ans = r;
  44. for(int j = 0; j < i; ++j) {
  45. ans = max(ans, get_y(node[j].x, node[j].y, node[i].x));
  46. }
  47. node[i].y = ans;
  48. printf("%.11f\n", (double)node[i].y);
  49. }
  50. }
  51. return 0;
  52. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注