探索flutter框架开发的app在移动应用市场的潜力与挑战
645
2022-10-21
Codeforces Round #354 (Div. 2) E (数学题)
E. The Last Fight Between Human and AI
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0,
with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x)
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
input
1 2-1?
output
Yes
input
2 100-1000001
output
Yes
input
4 5?1?1?
output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
题解:
输入一个P(x),没有系数,求可不可能P(x) = B(x)Q(x),其中Q(x)=x-k,由机器人先开始,计算人类会不会赢,并且局面可能是玩了几局之后的局面。
(x-k)|P(x)等价于P(k)==0,分两种情况考虑,if(k=0),谁先使得a[0]=0就谁赢。如果k!=0的话,注意到每一步都可以任意改变P(k)的值,因此只有最后一步是有用的,如果所有数都已经确定,那么检查P(k)是否为0,否则胜负取决于最后一步操作的先手。
AC代码:
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~