Codeforces Round #760 (Div. 3)
比赛链接
Codeforces Round #760 (Div. 3)
E. Singers' Tour
towns are arranged in a circle sequentially. The towns are numbered from 1 to in clockwise order. In the -th town, there lives a singer with a repertoire of minutes for each .
Each singer visited all towns in clockwise order, starting with the town he lives in, and gave exactly one concert in each town. In addition, in each town, the -th singer got inspired and came up with a song that lasts minutes. The song was added to his repertoire so that he could perform it in the rest of the cities.
Hence, for the -th singer, the concert in the -th town will last minutes, in the -th town the concert will last minutes, ..., in the -th town the duration of the concert will be , in the town minutes.
You are given an array of integer numbers, where is the total duration of concerts in the -th town. Reconstruct any correct sequence of positive integers or say that it is impossible.
Input
The first line contains one integer - the number of test cases. Then the test cases follow.
Each test case consists of two lines. The first line contains a single integer the number of cities. The second line contains integers - the total duration of concerts in -th city.
The sum of over all test cases does not exceed .
Output
For each test case, print the answer as follows:
If there is no suitable sequence , print NO. Otherwise, on the first line print YES, on the next line print the sequence of integers, where is the initial duration of repertoire of the -th singer. If there are multiple answers, print any of them.
Example
input
output
Note
Let's consider the 1-st test case of the example:
- the 1-st singer in the 1-st city will give a concert for 3 minutes, in the 2 -nd - for 6 minutes, in the 3 -rd - for 9 minutes;
- the 2 -nd singer in the 1 -st city will give a concert for 3 minutes, in the 2 -nd - for 1 minute, in the 3 -rd - for 2 minutes;
- the 3 -rd singer in the 1 -st city will give a concert for 6 minutes, in the 2 -nd - for 9 minutes, in the 3 -rd - for 3 minutes.
解题思路
构造,线性代数
即求解如下 个 元一次方程组:
当高斯消元的复杂度为 ,会超时,不妨先从小点的范围开始构造
构造答案前,将上面的等式加起来,有 ,则必须有
从 开始构造:
有如下等式:
做差,得 ,即 ,
得构造得到解:,注意 为正整数,且范围为
- 时间复杂度:
代码
F. Reverse
You are given two positive integers and . You can perform the following operation with : write it in its binary form without leading zeros, add 0 or 1 to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of .
For example:
- can be turned into via one operation: the binary form of is , if you add , reverse it and remove leading zeros, you will get , which is the binary form of .
- can be turned into via one operation: the binary form of is , if you add , reverse it and remove leading zeros, you will get , which is the binary form of .
- can be turned into via one operation: the binary form of is , if you add , reverse it and remove leading zeros, you will get , which is the binary form of .
- can be turned into via two operations: first you turn into and then into .
Your task is to find out whether can be turned into after a certain number of operations (possibly zero).
Input
The only line of the input contains two integers and .
Output
Print YES
if you can make equal to and NO
if you can't.
解题思路
dfs,记忆化搜索
对于一个数二进制,如果其后面没有 ,则如果在其后面加 的话翻转后前导 会去掉,相当于翻转原二进制串,即后面只能加 ,这就相当于只能在原二进制串前后加 ,且可翻转;如果一个数的二进制后面有 ,则有两种选择:将后面的 去掉,在后面加 ,这时两遍 即可
- 时间复杂度:
代码
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/16250728.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!