[关闭]
@Dmaxiya 2018-08-17T10:29:39.000000Z 字数 3426 阅读 974

Codeforces Round #456(Div.2)

Codeforces


Contests 链接:Codeforces Round #456(Div.2)
过题数:2
排名:702/8188

A. Tricky Alchemy

题意

有三种颜色的球,一个黄色球,需要两个黄色晶体合成,一个绿色球,需要一个黄色和一个蓝色晶体合成,蓝色球需要三个蓝色晶体合成。给出黄色球的个数 和蓝色球的个数 ,以及所需要的三种颜色的球,问还需要黄蓝两种颜色的球总共多少个?

数据范围

题解

按题意计算出所需要的黄色晶体和蓝色晶体数量,减去已经有的,相加即可。

过题代码

  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. LL x, y, z;
  21. LL a, b;
  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. while(scanf("%I64d%I64d", &a, &b) != EOF) {
  29. scanf("%I64d%I64d%I64d", &x, &y, &z);
  30. LL yellow = 2 * x + y;
  31. LL blue = y + 3 * z;
  32. LL ans = 0;
  33. LL tmp;
  34. tmp = yellow - a;
  35. if(tmp > 0) {
  36. ans += tmp;
  37. }
  38. tmp = blue - b;
  39. if(tmp > 0) {
  40. ans += tmp;
  41. }
  42. printf("%I64d\n", ans);
  43. }
  44. return 0;
  45. }

B. New Year's Eve

题意

给定 ,输出从 中,最多取 个数字,相异或,输出能够得到的最大的数字。

数据范围

题解

如果只能选一个数字,就输出 ,否则输出与 的二进制位相同的全为 的二进制。

过题代码

  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. LL n, k;
  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("%I64d%I64d", &n, &k) != EOF) {
  28. if(k == 1) {
  29. printf("%I64d\n", n);
  30. continue;
  31. }
  32. LL nn = n;
  33. int dig = 0;
  34. while(nn != 0) {
  35. ++dig;
  36. nn >>= 1;
  37. }
  38. printf("%I64d\n", ((1LL) << (dig)) - 1);
  39. }
  40. return 0;
  41. }

D. Fishes

题意

在一个 的鱼塘里随机撒网,这个渔网的大小为 想在这个鱼塘里放 只鱼,每个格子最多只能放一只鱼,问 要如何放鱼,才能够使得 捕到的鱼的期望最大,输出这个期望,精确到小数点后九位。

数据范围

题解

不论鱼怎么放,计算期望公式的分母都为 ,对于每一只放在 位置的鱼,它对分子的贡献为 ,而且可以确定,在鱼塘的中心位置放鱼,对分子的贡献最大,往外围依次减小,所以可以从中心开始放鱼,用优先队列进行宽搜 步,就可以得到最大的分子,除以分母就是结果。

过题代码

  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. struct Node {
  21. LL x, y;
  22. Node() {}
  23. Node(LL xx, LL yy) {
  24. x = xx;
  25. y = yy;
  26. }
  27. };
  28. bool operator<(const Node &a, const Node &b) {
  29. if(a.x == b.x) {
  30. return a.y < b.y;
  31. }
  32. return a.x < b.x;
  33. }
  34. LL n, m, r, k;
  35. set<Node> st;
  36. struct NNode {
  37. LL x, y;
  38. LL fenzi;
  39. NNode() {}
  40. NNode(LL xx, LL yy) {
  41. x = xx;
  42. y = yy;
  43. fenzi = (min(x + r - 1, n) - max(x, r) + 1) * (min(y + r - 1, m) - max(y, r) + 1);
  44. }
  45. };
  46. bool operator<(const NNode &a, const NNode &b) {
  47. return a.fenzi < b.fenzi;
  48. }
  49. priority_queue<NNode> que;
  50. const int dir[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
  51. bool In(LL x, LL y) {
  52. return x >= 1 && x <= n && y >= 1 && y <= m;
  53. }
  54. int main() {
  55. #ifdef LOCAL
  56. freopen("test.txt", "r", stdin);
  57. // freopen("out.txt", "w", stdout);
  58. #endif // LOCAL
  59. ios::sync_with_stdio(false);
  60. scanf("%I64d%I64d%I64d%I64d", &n, &m, &r, &k);
  61. LL fenmu = (m - r + 1) * (n - r + 1);
  62. LL fenzi = 0;
  63. que.push(NNode(n / 2 + 1, m / 2 + 1));
  64. st.insert(Node(n / 2 + 1, m / 2 + 1));
  65. while(!que.empty()) {
  66. NNode tmp = que.top();
  67. que.pop();
  68. fenzi += tmp.fenzi;
  69. --k;
  70. if(k == 0) {
  71. break;
  72. }
  73. LL x = tmp.x;
  74. LL y = tmp.y;
  75. for(int i = 0; i < 4; ++i) {
  76. LL xx = x + dir[i][0];
  77. LL yy = y + dir[i][1];
  78. if(In(xx, yy) && st.find(Node(xx, yy)) == st.end()) {
  79. que.push(NNode(xx, yy));
  80. st.insert(Node(xx, yy));
  81. }
  82. }
  83. }
  84. printf("%.15f\n", (double)fenzi / fenmu);
  85. return 0;
  86. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注