Codeforces Round #354 (Div. 2) E. The Last Fight Between Human and AI 数学
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 数学的更多相关文章
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #354 (Div. 2)-D
D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...
- Codeforces Round #354 (Div. 2)-C
C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...
- Codeforces Round #354 (Div. 2)-B
B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...
- Codeforces Round #354 (Div. 2)-A
A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth
题目链接: http://codeforces.com/contest/676/problem/D 题意: 如果两个相邻的格子都有对应朝向的门,则可以从一个格子到另一个格子,给你初始坐标xt,yt,终 ...
- Codeforces Round #354 (Div. 2) C. Vasya and String
题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
- 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 ...
随机推荐
- XSS注入常用语句
<script>alert('hello,gaga!');</script> //经典语句,哈哈! >"'><img src="javas ...
- 修改类不用重启Tomcat加载整个项目
可以修改类不用重启Tomcat加载整个项目(手工启动) 配置reloadable=true(自动重载) 使用Debug模式,前提是仅限于局部修改.(修改类不用重启--热加载) Tomcat轻小,而We ...
- haproxy支持的负载均衡算法详解
目前haproxy支持的负载均衡算法有如下8种: 1.roundrobin 表示简单的轮询,每个服务器根据权重轮流使用,在服务器的处理时间平均分配的情况下这是最流畅和公平的算法.该算法是动态的,对于实 ...
- vue系列之项目优化
webpack中的Code Splitting Code Splitting是什么以及为什么 在以前,为了减少HTTP请求,通常地,我们会把所有的代码都打包成一个单独的JS文件,但是,如果这个文件体积 ...
- ZooKeeper的典型应用场景
<从Paxos到Zookeeper 分布式一致性原理与实践>读书笔记 本文:总结脑图地址:脑图 前言 所有的典型应用场景,都是利用了ZK的如下特性: 强一致性:在高并发情况下,能够保证节点 ...
- SQL Server和Access数据读写
1.查询Access中数据的方法: select * from OpenRowSet('microsoft.jet.oledb.4.0',';database=c:/db2.mdb','select ...
- MySQL学习笔记:调用存储过程或函数报1418错误
问题 MySQL开启bin-log后,调用存储过程或者函数以及触发器时,会出现错误号为1418的错误: ERROR 1418 (HY000): This function has none of DE ...
- Failed to create the Java Virtual Machine
启动Zend Studio时出现Failed to create the Java VIrtual Machine 解决办法如下.打开安装目录下的ZendStudio.ini配置文件,作如下修改: 说 ...
- Oracle 提示符
http://blog.csdn.net/wyzxg/article/details/5647905
- 关于jedis2.4以上版本的连接池配置,及工具类
jedis.propertise 注意以前版本的maxAcitve和maxWait有所改变,JVM根据系统环境变量ServerType中的值 取不同的配置,实现多环境(测试环境.生产环境)集成. re ...