Educational Codeforces Round 117 ABCD 题解 (Java/C++)

A. Distance

题解

显然,当且仅当d(A, B)为偶数时有解。在有解的情况下,我们优先将目标的长度分配给Xc,如果不够再分配给Yc即可。

代码

Java

Submission #136751191 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #136751347 - Codeforces
Codeforces. Programming competitions and contests, programming community

B. Special Permutation

题解

我们先把a和b分别放到数组的两端,并将a和b标记为已使用。

然后对于前半段,我们依次把从n到1中未使用的数字放入数组。对于后半段,依次将b到1中未使用的数字放入数组。

如果发现找不到可用的数字,则表明无法构造。

代码

Java

Submission #136754381 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #136754520 - Codeforces
Codeforces. Programming competitions and contests, programming community

C. Chat Ban

题解

直接二分答案即可。

代码

Java

Submission #136756348 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #136756433 - Codeforces
Codeforces. Programming competitions and contests, programming community

D. X-Magic Pair

这个题目的关键在于发现对于指定的a和b,在一定范围内,每次操作后的被赋值的都是同一个变量。

Educational Codeforces Round 117 X-Magic Pair 题解 (Java/C++)
题解我们假设a<b,我们来观察各种可能的操作: 根据上图,我们发现,在0<a<b-2a时,a始终不会被替换掉,b会不断被b-a替代,直到存在某个c,使得b-(c+1)a<0且b-ca>0。
点击上面连接查看详细题解