1934.Codeforces Round 931 (Div. 2) - sol
20240301
。
A. Too Min Too Max
Given an array
of elements, find the maximum value of the expression: where
, , , and are four distinct indices of the array , with . Here
denotes the absolute value of .
还愣住了。
发现并不是每一个数都要和别的数做差,比如
所以一种非常贪心又简单的想法,我让
这样我们得到的答案是最大的,于是就做完了。代码。
B. Yet Another Coin Problem
You have
different types of coins, each with a value equal to one of the first triangular numbers: , , , , and . These coin types are available in abundance. Your goal is to find the minimum number of these coins required such that their total value sums up to exactly . We can show that the answer always exists.
。
赛时继续寄。
单纯地想回发现,是不是先用
但是你会发现过不了样例。
这时就可以分析一下,发现其实只会对于
那么我们可以稍微枚举一下,会发现当
于是可以直接特判一下即可。代码(不建议参考,还用 dp 预处理了一些)。
C. Find a Mine
This is an interactive problem.
You are given a grid with
rows and columns. The coordinates represent the cell on the grid, where ( ) is the row number counting from the top and ( ) is the column number counting from the left. It is guaranteed that there are exactly mines in the grid at distinct cells, denoted as and . You are allowed to make no more than queries to the interactor, and after these queries, you need to provide the location of one of the mines. In each query, you can choose any grid cell
, and in return, you will receive the minimum Manhattan distance from both the mines to the chosen cell, i.e., you will receive the value . Your task is to determine the location of one of the mines after making the queries.
。
又是一道交互题。
首先,只能询问
随机撒点去询问一定不现实,而只能询问
画图发现,我们可以从整个网格的四个角开始。
而这四个角得到的答案,一定是两个相邻的角对应一个地雷,并且只要我知道这两个距离,就可以得到地雷的位置了。
直接把距离之和与
作差就可以得到 坐标,这是画图容易发现的。
那么现在就需要知道每个角对应的是哪一个地雷了。
由于对应一个地雷的一定是相邻的两个角,所以我们可以先询问
假设他们两个对应的是同一个地雷,那么就可以得到这个地雷的具体位置
如果有,即返回
D1. XOR Break — Solo Version
This is the solo version of the problem. Note that the solution of this problem may or may not share ideas with the solution of the game version. You can solve and get points for both versions independently.
You can make hacks only if both versions of the problem are solved.
Given an integer variable
with the initial value of . A single break operation consists of the following steps:
- Choose a value
such that and . - Update
by either setting or setting . Determine whether it is possible to transform
into using a maximum of break operations. If it is, provide the sequence of operations required to achieve . You don't need to minimize the number of operations.
Here
denotes the bitwise XOR operation.
。
讨论不周到提前下播了。
感觉被
给出这个条件,第一反应就是去拆位,对于每一维去讨论让他满足条件。
但发现完全不用,只要
那什么时候不满足条件呢?
容易发现,当
但是这种情况就是没有救的吗?
我们发现只要这一位前面在
即通过把最高位的
比如刚才那种情况,我们可以把
而当前面只有一个
这样我们就做完了,其实只需要最多两步操作啊。代码。
D2. XOR Break — Game Version
This is an interactive problem.
This is the game version of the problem. Note that the solution of this problem may or may not share ideas with the solution of the solo version. You can solve and get points for both versions independently.
Alice and Bob are playing a game. The game starts with a positive integer
, with players taking turns. On each turn of the game, the following sequence of events takes place:
- The player having the integer
breaks it into two integers and , where , and . - If no such
, exist, the player loses. - Otherwise, the opponent does either select the integer
or . - The game continues with the selected integer. The opponent will try to break it.
As Alice, your goal is to win. You can execute a maximum of
break operations. You have the choice to play first or second. The system will act for Bob. Here
denotes the bitwise XOR operation.
。
简单题,可惜赛时没看下播了。
这种博弈题,一看就一定存在必胜策略,于是你可以直接写一个 dp 看看,感觉就和二进制
因为是
那么容易发现,当
而当
于是这样我们每一次操作都拿出一个
最后通过二进制
样例居然是错的。 代码。
E. Weird LCM Operations
Given an integer
, you construct an array of integers, where for all integers in the range . An operation on this array is defined as follows:
- Select three distinct indices
, , and from the array, and let , , and . - Update the array as follows:
, , and , where represents the least common multiple. Your task is to provide a possible sequence of operations, containing at most
operations such that after executing these operations, if you create a set containing the greatest common divisors (GCDs) of all subsequences with a size greater than , then all numbers from to should be present in this set. After all the operations
should hold for all . We can show that an answer always exists.
。
好题。
首先,发现限制
每次操作三个数,全部操作完也需要
大胆猜测一下,分析发现确实好像是这样的。
发现对于
而其他的数却不能得到,所以我们只需要对后一半的数讨论。
再来分析一下,感觉一个数被操作两次是不现实的,第一是这样次数会超,第二,这样的 gcd 会不会变大,从而就失去效果了?
那么我们尝试用只操作一次的策略完成,先从满足
-
当
是奇数的时候,他们三个一定是互质的,那么我们就直接操作 ,这样会得到 ,而两两做 gcd,就可以满足条件。 -
当
是偶数时, 和 就会有公因子 ,这是不利的,所以我们考虑把其中一个 。 是 的倍数时, 也是偶数,是不满足条件的,所以我们考虑用 ,操作 。 不是 的倍数,则 是奇数,我们就直接操作 即可。
这样的操作可以刚好在做 gcd 时用上
这个公因子,从而可以得到这四个数。
按照这样的操作,我们三个三个地处理就是可以完成的。
而如果
发现我们可以用上
这样就做完了,代码也是好写的,感觉突破口就在于对限制的大胆猜想。代码。
Conclusion
- 对于每道题的限制要加以分析,可能会成为突破口,但如果有更优的策略,也不要被限制误导了。(D1,E)
- 有关 gcd,lcm 的题目一定要尽量构造 互质 的情况。(E)
本文作者:H_W_Y
本文链接:https://www.cnblogs.com/H-W-Y/p/18050338/cf1934
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步