Codeforces Round #525 (Div. 2) Solution

A. Ehab and another construction problem

Water.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int x;
 5 
 6 int main()
 7 {
 8     while (scanf("%d", &x) != EOF)
 9     {
10         int a = -1, b = -1;
11         for (int i = 1; i <= x && a == -1 && b == -1; ++i)
12         {
13             for (int j = i; j <= x; ++j)
14             {
15                 if (j % i == 0 && i * j > x && j / i < x)
16                 {
17                     a = j, b = i;
18                     break;
19                 }
20             }    
21         }
22         if (a == -1) puts("-1");
23         else printf("%d %d\n", a, b);
24     }
25     return 0;
26 }
View Code

B. Ehab and subtraction

Water.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define N 100010
 5 int n, k;
 6 
 7 int main()
 8 {
 9     while (scanf("%d%d", &n, &k) != EOF)
10     {
11         priority_queue <int, vector <int>, greater <int> > q;
12         for (int i = 1, x; i <= n; ++i)
13         {
14             scanf("%d", &x);
15             if (x) q.push(x);
16         }
17         int add = 0;
18         for (int kk = 1; kk <= k; ++kk)
19         {
20             while (!q.empty() && q.top() == add) q.pop();     
21             if (q.empty()) puts("0");
22             else
23             {
24                 int top = q.top(); q.pop();
25                 top -= add;
26                 add += top;
27                 printf("%d\n", top);
28             }
29         }
30     }
31     return 0;
32 }
View Code

C. Ehab and a 2-operation task

Solved.

题意:

有两种操作

$将前j个数全都加上x$

$将前j个数全都mod x$

要求用不超过$n + 1 次操作,使得给定序列变成严格的上升序列$

思路:

先全部加上一个较大的数$D$

然后每一次模一个数$D + a_i - i之后使得a_i 变成 i, 并且这样可以保证D + a_i - i > i - 1 只要D足够大$

那么前面已经弄好的数不会受到影响

操作数刚好$n + 1$

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define N 2010
 5 int d = (int)5e5; 
 6 int n;
 7 
 8 int main()
 9 {
10     while (scanf("%d", &n) != EOF)
11     {
12         printf("%d\n", n + 1);
13         printf("1 %d %d\n", n, d);
14         for (int i = 1, x; i <= n; ++i)
15         {
16             scanf("%d", &x);
17             printf("2 %d %d\n", i, (x + d - i)); 
18         }
19     }
20     return 0;
21 }
View Code

D. Ehab and another another xor problem

Upsolved.

题意:

交互题。

要求猜两个数 $(a, b)$

每次可以给出询问$c, d$

根据$a \oplus c 和 b \oplus d 的大小关系给出1 0 -1 三种状态$

要求根据这些关系得出$(a, b), 询问次数<= 62$

思路:

此处我们约定$(x, y) 表示给出询问(? x  y)$

先考虑$a == b 的情况,那么我们只需要每一次按位给出询问$

$此处约定i 表示第i位 , 给出询问 (1 << i, 0) 根据所给结果即可判断当前位为0还是1$

注意到对于两个数$a, b 根据二进制拆分之后,如果它们最高位所在位置不同$

那么谁的最高位高谁就更大

$那么我们从高位往低位确定,用aa, bb 表示a, b 中高位已经确定的数$

我们用$zero 表示 a 和 b 的大小关系,这个可以通过给出询问(0, 0) 得到$

$这样就可以每一次消除影响,判断当前位是否相同,或者大小关系$

猜你喜欢

转载自www.cnblogs.com/Dup4/p/10068891.html