[关闭]
@Dmaxiya 2018-08-17T02:23:18.000000Z 字数 3965 阅读 839

Codeforces Round #443 (Div. 2)

Codeforces


Contests 链接:Codeforces Round #443 (Div. 2)
过题数:3
排名:162/10198

A. Borya's Diagnosis

题意

病得很重,所以他需要按顺序依次到多个医生那里看病,第 个医生的第一次上班时间为 ,之后每隔 天上一次班,且每个医生看病都需要前一个医生的诊断结果,由于看病需要的时间非常久,所以 每天只能去一个医生那里看病,他必须看到最后一个医生才能确诊。问如果给定 个医生的第一天上班时间 和上班周期 最少需要多少天才能确诊。

输入

第一行包括一个整数 ,接下去 行每行两个整数

输出

输出 确诊的最短时间。

样例

输入 输出 提示
3
2 2
1 2
2 2
4 可以在第 天去看病。
2
10 1
6 5
11 可以在第 天看病。

题解

按照题意模拟。

过题代码

  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 <bitset>
  16. #include <algorithm>
  17. #include <ctime>
  18. #include <functional>
  19. #include <iomanip>
  20. using namespace std;
  21. #define LL long long
  22. LL n, s, d;
  23. LL day;
  24. int main() {
  25. #ifdef LOCAL
  26. freopen("test.txt", "r", stdin);
  27. // freopen("out.txt", "w", stdout);
  28. #endif
  29. ios::sync_with_stdio(false);
  30. while(scanf("%I64d", &n) != EOF) {
  31. day = 0;
  32. for(int i = 0; i < n; ++i) {
  33. scanf("%I64d%I64d", &s, &d);
  34. if(day < s) {
  35. day = s;
  36. } else {
  37. day = ((day - s) / d + 1) * d + s;
  38. }
  39. }
  40. printf("%I64d\n", day);
  41. }
  42. return 0;
  43. }

B. Table Tennis

题意

个人排成一队进行乒乓球比赛,最开始队首的两个人出队进行比赛,失败的人到队尾等待下次比赛,胜利的人与当前队首的人继续进行比赛,连续 场比赛胜利的人获得最终的胜利。每个人都有不同的 值,两个 值不同的人比赛, 值高的人将获胜,求获得最终胜利者的 值。

输入

第一行包含两个整数 ,第二行为 个整数 ,表示每个人的 值,每个 值都是不同的。

输出

输出最终获胜者的 值。

样例

输入 输出 提示
2 2
1 2
2
4 2
3 1 2 4
3 比赛, 获胜且 到队尾, 再和 比赛, 次获得胜利,连续两场
比赛获得胜利,因此 最终获胜。
6 2
6 5 3 1 2 4
6
2 10000000000
2 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 <bitset>
  16. #include <algorithm>
  17. #include <ctime>
  18. #include <functional>
  19. #include <iomanip>
  20. using namespace std;
  21. #define LL long long
  22. const int maxn = 600;
  23. LL n, k;
  24. int num;
  25. queue<int> que;
  26. int main() {
  27. #ifdef LOCAL
  28. freopen("test.txt", "r", stdin);
  29. // freopen("out.txt", "w", stdout);
  30. #endif
  31. ios::sync_with_stdio(false);
  32. while(scanf("%I64d%I64d", &n, &k) != EOF) {
  33. while(!que.empty()) {
  34. que.pop();
  35. }
  36. for(int i = 1; i <= n; ++i) {
  37. scanf("%d", &num);
  38. que.push(num);
  39. }
  40. if(k > n) {
  41. printf("%I64d\n", n);
  42. } else {
  43. int win = 0;
  44. num = que.front();
  45. que.pop();
  46. while(true) {
  47. if(num > que.front()) {
  48. int tmp = que.front();
  49. que.pop();
  50. que.push(tmp);
  51. ++win;
  52. } else {
  53. que.push(num);
  54. num = que.front();
  55. que.pop();
  56. win = 1;
  57. }
  58. if(win >= k) {
  59. break;
  60. }
  61. }
  62. printf("%d\n", num);
  63. }
  64. }
  65. return 0;
  66. }

C. Short Program

题意

一个程序由 个位运算符以及 之间的数字组成,程序的输入为一个 范围内的整数,输出是将这个整数按顺序进行位运算后的结果,但是这个程序太长了,现在要将这个程序减少到五行以内,但是能实现的功能和原来的程序是一样的,输出最终的程序。

输入

第一行包含一个整数 ,接下去 行每行一个字符与一个整数 ,字符 '&' '|' '^' 对应位运算中的与、或、异或运算。

输出

输出第一行为一个整数 ,表示即将输出的程序的行数,接下去 行输出格式与输入格式相同,执行的效果对于任意数字都能得到和原程序得到的结果相同。

样例

输入 输出 提示
3
3
^ 2
1
2
3
^ 2
3
& 1
& 3
& 5
1
& 1
假设 为对程序输入的数字,则
3
^ 1
^ 2
^ 3
0

题解

一个数组来记每一位的状态:一定为 、一定为 、一定取反、一定等于原来的值,例如某个数字的某一位和 相与,则低 位一定等于原来的值,高位一定等于 ,其他运算根据运算规则确定状态,最后可以将一定为 的位用 (& 0) 表示,将一定为 的位用 (| 1) 表示,一定取反的位用 ('^' 1) 表示,一定和原来相等的位用 ('|' 0) 或者 ('&' 1) 或者 ('^' 0) 表示,最后只需要 个运算符就可以表示所有运算。

过题代码

  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 <bitset>
  16. #include <algorithm>
  17. #include <ctime>
  18. #include <functional>
  19. #include <iomanip>
  20. using namespace std;
  21. #define LL long long
  22. const int maxn = 20;
  23. int n, c;
  24. char ch[2];
  25. int num[maxn];
  26. int main() {
  27. #ifdef LOCAL
  28. freopen("test.txt", "r", stdin);
  29. // freopen("out.txt", "w", stdout);
  30. #endif
  31. ios::sync_with_stdio(false);
  32. while(scanf("%d", &n) != EOF) {
  33. memset(num, 0, sizeof(num));
  34. for(int i = 0; i < n; ++i) {
  35. scanf("%s%d", ch, &c);
  36. for(int j = 0; j < 10; ++j) {
  37. int tmp = ((c >> j) & 1);
  38. if(ch[0] == '&') {
  39. if(tmp == 0) {
  40. num[j] = 3;
  41. }
  42. } else if(ch[0] == '|') {
  43. if(tmp == 1) {
  44. num[j] = 2;
  45. }
  46. } else if(ch[0] == '^') {
  47. if(tmp == 1) {
  48. num[j] ^= 1;
  49. }
  50. }
  51. }
  52. }
  53. int Xor = 0, Or = 0, And = 1023;
  54. for(int i = 0; i < 10; ++i) {
  55. if(num[i] == 1) {
  56. Xor |= (1 << i);
  57. } else if(num[i] == 2) {
  58. Or |= (1 << i);
  59. } else if(num[i] == 3) {
  60. And ^= (1 << i);
  61. }
  62. }
  63. printf("3\n");
  64. printf("| %d\n", Or);
  65. printf("^ %d\n", Xor);
  66. printf("& %d\n", And);
  67. }
  68. return 0;
  69. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注