[关闭]
@Dmaxiya 2018-08-17T10:18:40.000000Z 字数 3928 阅读 902

Codeforces Round #461 (Div. 2)

Codeforces


Contests 链接:Codeforces Round #461 (Div. 2)
过题数:4
排名:230/11398

A. Cloning Toys

题意

有一个可以克隆玩具的机器,如果放入一个原始玩具,则会获得一个额外的原始玩具和一个克隆玩具,如果放入一个克隆玩具,则会获得两个额外的克隆玩具, 最初有 个原始玩具,他想要获得 个克隆玩具和 个原始玩具,问他能否通过这个机器得到。

输入

输入包含两个整数

输出

如果可以,则输出 ,否则输出 ,大小写任意。

样例

输入 输出 提示
6 3 Yes 可以通过放入两次原始玩具和两次克隆玩具获得 个克隆玩具和 个原始玩具。
4 2 No
1000 1001 Yes

题解

原始玩具的个数至少为 ,且如果原始玩具的个数为 ,则他不可能有克隆玩具,如果他有克隆玩具,则克隆玩具的个数至少为 ,除了通过原始玩具得到的 个克隆玩具,剩下的所有克隆玩具个数应该为偶数。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. int x, y;
  19. int main() {
  20. #ifdef Dmaxiya
  21. freopen("test.txt", "r", stdin);
  22. #endif // Dmaxiya
  23. ios::sync_with_stdio(false);
  24. while(scanf("%d%d", &x, &y) != EOF) {
  25. if(x < y - 1 || y < 1) {
  26. printf("No\n");
  27. continue;
  28. }
  29. if(y == 1 && x != 0) {
  30. printf("No\n");
  31. continue;
  32. }
  33. x -= y - 1;
  34. if(x % 2 == 0) {
  35. printf("Yes\n");
  36. } else {
  37. printf("No\n");
  38. }
  39. }
  40. return 0;
  41. }

B. Magic Forest

题意

给定数字 ,问有多少个整数对 满足下面的条件:

  1. 为三边可以构成一个非退化的三角形。

输入

输入包含一个整数

输出

输出满足条件的整数对的个数。

样例

输入 输出 提示
6 1 只有 一组整数对满足条件。
10 2

题解

暴力从 枚举 的值,用异或得到 的值进行判断。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. int n;
  19. LL ans;
  20. int main() {
  21. #ifdef Dmaxiya
  22. freopen("test.txt", "r", stdin);
  23. #endif // Dmaxiya
  24. ios::sync_with_stdio(false);
  25. while(scanf("%d", &n) != EOF) {
  26. ans = 0;
  27. for(int i = 1; i <= n; ++i) {
  28. for(int j = i; j <= n; ++j) {
  29. int k = i ^ j;
  30. if(k >= j && k <= n && i + j > k) {
  31. ++ans;
  32. }
  33. }
  34. }
  35. printf("%I64d\n", ans);
  36. }
  37. return 0;
  38. }

C. Cave Painting

题意

给定整数 ,问对于所有的 ,是否 的值都不相同。

输入

输入包含两个整数

输出

如果 满足条件,则输出 ,否则输出 ,大小写任意。

样例

输入 输出 提示
4 4 No 取模的值相等。
5 3 Yes

题解

开始, 的值一定为 ,对 取模的值要不等于 ,则只能 ,以此类推,对 取模的值必须等于 ,因此可以建立一个同余方程,可以发现要满足对 内所有的数取模都等于 的解是呈阶乘增长的,因此只要暴力从 进行判断,一旦不满足条件就跳出循环,实际需要判断的次数是很少的,远远达不到

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. LL n, k;
  19. int main() {
  20. #ifdef Dmaxiya
  21. freopen("test.txt", "r", stdin);
  22. #endif // Dmaxiya
  23. ios::sync_with_stdio(false);
  24. while(scanf("%I64d%I64d", &n, &k) != EOF) {
  25. bool flag = true;
  26. for(LL i = 1; i <= k; ++i) {
  27. if(n % i != i - 1) {
  28. flag = false;
  29. break;
  30. }
  31. }
  32. if(flag) {
  33. printf("Yes\n");
  34. } else {
  35. printf("No\n");
  36. }
  37. }
  38. return 0;
  39. }

D. Robot Vacuum Cleaner

题意

定义一个只包含 的字符串的权值为字符串中 子序列的个数,现在给定 个字符串 ,问将这些字符串按任意顺序连接起来能够得到的最大的权值。

输入

第一行为一个整数 ,接下去 行每行一个字符串 ,每一个字符串都只包含字符

输出

输出将所有字符串按任意顺序连接起来之后得到的最大的权值。

样例

输入 输出 提示
4
ssh
hs
s
hhhs
18 最优的连接方式为
2
h
s
1

题解

首先统计每个字符串中 的数量 ,然后贪心将所有字符串进行排序,排序的规则为:

  1. 如果字符串 排在 之前,可以得到 子序列,反之亦然,记为
  2. 如果 ,则将 值大的放在前面,否则将 中值大的放在前面。

最后扫一遍排序后的字符串统计 子序列的个数。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. const int maxn = 100000 + 100;
  19. struct Node {
  20. int Index;
  21. LL cnts, cnth;
  22. };
  23. bool operator<(const Node &a, const Node &b) {
  24. LL aa = a.cnts * b.cnth;
  25. LL bb = b.cnts * a.cnth;
  26. if(aa == bb) {
  27. return a.cnts > b.cnts;
  28. }
  29. return aa > bb;
  30. }
  31. int n;
  32. string str[maxn];
  33. Node node[maxn];
  34. int main() {
  35. #ifdef Dmaxiya
  36. freopen("test.txt", "r", stdin);
  37. #endif // Dmaxiya
  38. ios::sync_with_stdio(false);
  39. while(cin >> n) {
  40. for(int i = 0; i < n; ++i) {
  41. cin >> str[i];
  42. node[i].Index = i;
  43. node[i].cnts = node[i].cnth = 0;
  44. for(int j = 0; str[i][j]; ++j) {
  45. if(str[i][j] == 's') {
  46. ++node[i].cnts;
  47. } else {
  48. ++node[i].cnth;
  49. }
  50. }
  51. }
  52. sort(node, node + n);
  53. LL cnt = 0, ans = 0;
  54. for(int i = 0; i < n; ++i) {
  55. int ii = node[i].Index;
  56. for(int j = 0; str[ii][j]; ++j) {
  57. if(str[ii][j] == 's') {
  58. ++cnt;
  59. } else {
  60. ans += cnt;
  61. }
  62. }
  63. }
  64. printf("%I64d\n", ans);
  65. }
  66. return 0;
  67. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注