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 ...
随机推荐
- Testbench学习——$fopen/$display/$fclose
昨天在用Vivado写Testbench顶层时,为了以后便于数据的存储导出分析,需要用的文件数据记录的功能,于是,下面谈谈$fopen/$display/$fclose这三者的用法. $fopen—— ...
- aarch64_g2
ghc-cryptonite-devel-0.21-1.fc26.aarch64.rpm 2017-02-28 01:28 3.1M fedora Mirroring Project ghc-css- ...
- session的本质及如何实现共享?
为什么有session? 首先大家知道,http协议是无状态的,即你连续访问某个网页100次和访问1次对服务器来说是没有区别对待的,因为它记不住你. 那么,在一些场合,确实需要服务器记住当前用户怎么办 ...
- jquery 绑定,mvc和webform的三种方式
asp.net里的绑定方式,on的绑定方式无效 $('#SelCommandType').bind('click', function () { }); mvc里的绑定方式 $('#DownList' ...
- 教您如何进行SQL跨表更新
SQL跨表更新数据是在使用SQL数据库中比较常用的,下面就将为您详细介绍SQL跨表更新数据的步骤,希望对您学习SQL跨表更新数据有所启迪. 原始数据如下,首先是表结构 A_dept的初始数据 A_em ...
- Chrome+XX_Net的上网渠道
本页面将详细演示如何在一台全新的Windows7电脑上架设起Chrome+XX_Net的上网渠道. 本文包含以下部分: 下载和安装Chrome浏览器 获取和运行XX-Net 设置代理 手动导入证书(备 ...
- ubuntu 休眠后窗口边缘出现花边的解决方案
可以确定是nvidia显卡的问题,详细的解决方案请参见:这里 临时的解决方案: compize --replace 永久性的解决方案: sudo add-apt-repository ppa:grap ...
- hdu 5131 (2014广州现场赛 E题)
题意:对给出的好汉按杀敌数从大到小排序,若相等,按字典序排.M个询问,询问名字输出对应的主排名和次排名.(排序之后)主排名是在该名字前比他杀敌数多的人的个数加1,次排名是该名字前和他杀敌数相等的人的个 ...
- css实现360导航首页超链接变色
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【LOJ】#2290. 「THUWC 2017」随机二分图
题解 看了一眼觉得是求出图对图统计完美匹配的个数(可能之前做过这样模拟题弃疗了,一直心怀恐惧... 然后说是统计一下每种匹配出现的概率,也就是,当前左边点匹配状态为S,右边点匹配状态为T,每种匹配出现 ...