E. The Last Fight Between Human and AI

题目连接:

http://codeforces.com/contest/676/problem/E

Description

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) is also some polynomial.

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 ≤ 10 000). 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.

Sample Input

1 2

-1

?

Sample Output

Yes

Hint

题意

给你一个P(x),系数都没有决定,问你可不可能P(x) = B(x)Q(x)

其中Q(x)=x-k

由机器人先开始,问你会不会赢……

局面可能是给你玩了几局之后的局面。

题解:

(x-k)|P(x)等价于P(k)==0

分两种情况考虑

如果k=0的话,谁先使得a[0]=0就好了

如果k!=0的话,注意到每一步都可以任意改变P(k)的值,因此只有最后一步是有用的,如果所有数都已经确定,那么检查P(k)是否为0,否则胜负取决于最后一步操作的先手。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int inf = 0x3f3f3f3f;
int a[maxn],cnt,n,k;
string s;
int main()
{
scanf("%d%d",&n,&k);n++;
for(int i=0;i<n;i++)
{
cin>>s;
if(s[0]=='?')a[i]=inf;
else{
int p=0;
if(s[0]=='-')p=1;
for(int j=p;j<s.size();j++)
a[i]=a[i]*10+(int)(s[j]-'0');
if(s[0]=='-')a[i]=a[i]*(-1);
cnt++;
}
}
if(k==0)
{
if(a[0]==inf)
{
if(cnt%2==1)printf("YES\n");
else printf("NO\n");
}
else if(a[0])printf("NO\n");
else printf("YES\n");
}
else
{
if(cnt<n)
{
if(n%2==1)printf("NO\n");
else printf("YES\n");
}
else
{
long long now = 0;
for(int i=n-1;i>=0 && abs(now)<1e14;i--)
now=1LL*now*k+a[i];
printf("%s\n",(now ? "No" : "Yes"));
}
}
}

Codeforces Round #354 (Div. 2) E. The Last Fight Between Human and AI 数学的更多相关文章

  1. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  2. Codeforces Round #354 (Div. 2)-D

    D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...

  3. Codeforces Round #354 (Div. 2)-C

    C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...

  4. Codeforces Round #354 (Div. 2)-B

    B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...

  5. Codeforces Round #354 (Div. 2)-A

    A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...

  6. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth

    题目链接: http://codeforces.com/contest/676/problem/D 题意: 如果两个相邻的格子都有对应朝向的门,则可以从一个格子到另一个格子,给你初始坐标xt,yt,终 ...

  7. Codeforces Round #354 (Div. 2) C. Vasya and String

    题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...

  8. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

  9. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth bfs

    D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus h ...

随机推荐

  1. 乐视mysql面试题【转】

    最近,朋友去乐视面试了mysql DBA,以下是我据整理的乐视mysql面试题答案,供大家参考 1. MYISAM和INNODB的不同?答:主要有以下几点区别:   a)构造上的区别     MyIS ...

  2. Linux下简单粗暴使用rsync实现文件同步备份【转】

    这篇来说说如何安全的备份,还有一点不同的是上一篇是备份服务器拉取数据,这里要讲的是主服务器如何推送数据实现备份. 一.备份服务器配置rsync文件 vim /etc/rsyncd.conf #工作中指 ...

  3. Unity教程之-Unity3d中针对Android Apk的签名验证(C#实现)

    当Unity开发的游戏以Android Apk的形式发布之后,经常会遇到的一种情况就是别人对我们的游戏进行二次打包,也就是用他们的签名替换掉我们的签名,从而堂而皇之的将胜利果实占为己有.面对这样的情况 ...

  4. Python开发环境(2):启动Eclipse时检测到PYTHONPATH发生改变

    OS:Windows 10家庭中文版,Eclipse:Oxygen.1a Release (4.7.1a),PyDev:6.3.2 4月25日,在Eclipse上安装了PyDev(前面博文有记录),并 ...

  5. java基础63 JavaScript中的Number、Math、String、Date对象(网页知识)

    本文知识点(目录): 1.Number对象    2.Math对象    3.String对象    4.Date对象 (日历例子) 1.Number对象 1.1.Number对象的创建方式 方式1: ...

  6. ubuntu14.04 使用传统的netcat

    Ubuntu上默认安装的是netcat-openbsd,而不是经典的netcat-traditional. 网上例子很多都是以netcat-traditional为例. sudo apt-get -y ...

  7. HBase混布MapReduce集群学习记录

    一.准备工作 1.1 部署环境 集群规模大概260多台,TSC10机型,机型参数如下: > 1个8核CPU(E5-2620v4) > 64G内存 > HBA,12*4T SATA,1 ...

  8. js对象的属性:数据(data)属性和访问器(accessor)属性

    此文为转载,原文: 深入理解对象的数据属性与访问器属性 创建对象的方式有两种:第一种,通过new操作符后面跟Object构造函数,第二种,对象字面量方式.如下 var person = new Obj ...

  9. sicily 1051. Biker's Trip Odomete

    DescriptionMost bicycle speedometers work by using a Hall Effect sensor fastened to the front fork o ...

  10. xtrabckup备份报错:Failed to connect to MySQL server: Can't connect to local MySQL server through socket '/data/mysql/mysql.sock' (2).

    1.做软连接 [root@xxxxxx:/data/backup/log]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock [root@xxxxxxx ...