Codeforces Round #525 (Div. 2) Solution
阿新 • • 發佈:2018-12-05
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 == -1View Code; ++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 }
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 whileView Code(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 }
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) 得到$
$這樣就可以每一次消除影響,判斷當前位是否相同,或者大小關係$