[关闭]
@Dmaxiya 2018-08-17T10:30:07.000000Z 字数 3931 阅读 924

Codeforces Round #454(Div.2)

Codeforces


Contests 链接:Codeforces Round #454(Div.2)
过题数:3
排名:628/5566

A. Masha and Bears

题意

有三只熊,熊爸熊妈和熊儿子,熊爸能爬得上并且喜欢大车,熊妈能爬得上中车且喜欢中车,熊儿子能爬得上小车且喜欢小车, 能爬得上小车且只喜欢小车。对于一只体积为 的角色,如果它能爬得上一辆体积为 车,它必须满足条件 ,如果它喜欢一辆车,那么它必须满足条件 ,现在给出三只熊和 的体积 ,问能否找到满足以上条件的三辆车,如果能找得到,则输出这三辆车的体积,否则输出

数据范围

题解

分几种情况讨论一下就行了,情况比较多,所以 语句比较多。要注意 只喜欢小车的条件。

过题代码

  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, d;
  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", &a, &b, &c, &d) != EOF) {
  28. a *= 2;
  29. b *= 2;
  30. if(d <= c) {
  31. if(2 * d >= c && 2 * d < b) {
  32. printf("%d\n%d\n%d\n", a, b, c);
  33. } else {
  34. printf("-1\n");
  35. }
  36. } else {
  37. if(d <= 2 * c) {
  38. c = d;
  39. if(d * 2 < b) {
  40. printf("%d\n%d\n%d\n", a, b, c);
  41. } else {
  42. printf("-1\n");
  43. }
  44. } else {
  45. printf("-1\n");
  46. }
  47. }
  48. }
  49. return 0;
  50. }

B. Tic-Tac-Toe

题意

给定一个 的九宫格,对于每个宫格,都是一个 的方阵,两个人轮流下落子,如果一个人落在某个宫格的第 行第 列,那么另一个人就可以在第 行第 列的宫格中的任意一个位置落子,如果第 行第 列的宫格已经落满了子,那么另一个人可以在整个宫格中的任意一个地方落子。给定初始局面,和最后一个落子的坐标,输出另一个人可能可以落子的位置。

数据范围

题解

按照题意模拟就行了。

过题代码

  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, m;
  21. char str[3][3][3][10];
  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. for(int i = 0; i < 9; ++i) {
  29. for(int j = 0; j < 3; ++j) {
  30. scanf("%s", str[i / 3][j][i % 3]);
  31. }
  32. }
  33. scanf("%d%d", &n, &m);
  34. --n;
  35. --m;
  36. int row = n % 3;
  37. int col = m % 3;
  38. bool flag = false;
  39. for(int i = 0; i < 3; ++i) {
  40. for(int j = 0; j < 3; ++j) {
  41. if(str[row][col][i][j] == '.') {
  42. flag = true;
  43. }
  44. }
  45. }
  46. if(flag) {
  47. for(int i = 0; i < 3; ++i) {
  48. for(int j = 0; j < 3; ++j) {
  49. if(str[row][col][i][j] == '.') {
  50. str[row][col][i][j] = '!';
  51. }
  52. }
  53. }
  54. } else {
  55. for(int i = 0; i < 3; ++i) {
  56. for(int j = 0; j < 3; ++j) {
  57. for(int ii = 0; ii < 3; ++ii) {
  58. for(int jj = 0; jj < 3; ++jj) {
  59. if(str[i][j][ii][jj] == '.') {
  60. str[i][j][ii][jj] = '!';
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }
  67. for(int i = 0; i < 9; ++i) {
  68. for(int j = 0; j < 3; ++j) {
  69. if(j != 0) {
  70. printf(" ");
  71. }
  72. printf("%s", str[i / 3][j][i % 3]);
  73. }
  74. printf("\n");
  75. if(i % 3 == 2) {
  76. printf("\n");
  77. }
  78. }
  79. return 0;
  80. }

C. Shockers

题意

有一个人,他要猜一个字符,如果他说的单词中包含了这个字符,他就会被 一下,如果他说的单词中没有包含这个字符,他就没事,他还可以猜这个字符,如果他猜错了,他仍然会被 一下。因为这个人反应比较慢,所以他本来早就可以猜出答案了,结果却要被多 几下才能猜到最后的答案,问如果按照他的提问顺序,他可以少被 几下?

数据范围

题解

用两个集合 来维护,先把 初始化,把 的小写字符全都放进去,对于后面每一次被 的提问,都取当前单词和 里的字符的交集,对于每一次没有被 的提问,都把当前的单词记录到 集合里,每次都从 集合里删去 集合里的字符。当 集合的大小为 时,就可以得到答案,对于后面的提问,就按照题意来模拟就行了。

过题代码

  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. char ch[2];
  23. char str[maxn];
  24. set<char> st, Not;
  25. char ans;
  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", &n) != EOF) {
  33. ans = '\0';
  34. int ccnt = 0;
  35. st.clear();
  36. Not.clear();
  37. for(char c = 'a'; c <= 'z'; ++c) {
  38. st.insert(c);
  39. }
  40. for(int i = 0; i < n; ++i) {
  41. scanf("%s%s", ch, str);
  42. if(ans != '\0') {
  43. if(ch[0] == '!') {
  44. ++ccnt;
  45. } else if(ch[0] == '?' && str[0] != ans) {
  46. ++ccnt;
  47. }
  48. } else {
  49. if(ch[0] == '!') {
  50. set<char> tmp;
  51. for(int j = 0; str[j]; ++j) {
  52. if(st.find(str[j]) != st.end()) {
  53. tmp.insert(str[j]);
  54. }
  55. }
  56. st = tmp;
  57. } else if(ch[0] == '.') {
  58. for(int j = 0; str[j]; ++j) {
  59. Not.insert(str[j]);
  60. }
  61. } else if(ch[0] == '?') {
  62. for(int j = 0; str[j]; ++j) {
  63. Not.insert(str[j]);
  64. }
  65. }
  66. for(set<char>::iterator it = Not.begin(); it != Not.end(); ++it) {
  67. st.erase(*it);
  68. }
  69. if(st.size() == 1) {
  70. set<char>::iterator it = st.begin();
  71. ans = *it;
  72. }
  73. }
  74. }
  75. printf("%d\n", ccnt);
  76. }
  77. return 0;
  78. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注