链接

Codeforces 676E The Last Fight Between Human and AI

题意

给一个多项式,有些系数不确定。人和机器轮流填系数,系数可以是任何数,问是否能使得最后的多项式整除 x-k

思路

整除x-k就等价 x=k时,多项式为0. 系数可以是任何数的话就能得到任何结果,只要人是否是填最后一个就行。

另外分 k=0 和 k<>0两种情况考虑。

代码

#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string> #define LL long long
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN 100005
using namespace std; int a[MAXN];
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int n, k;
while(~scanf("%d%d", &n, &k)){
int unk = 0;
for(int i = 0; i <= n; ++i){
char s[20];
scanf("%s", s);
if(s[0] == '?'){
a[i] = INF;
++unk;
}
else{
a[i] = atoi(s);
}
}
if(k == 0){
if(a[0] == 0){
printf("Yes\n");
}
else if(a[0] == INF){
if((n + 1 - unk) & 1){
printf("Yes\n");
}
else{
printf("No\n");
}
}
else{
printf("No\n");
}
}
else{
if(unk > 0){
if((n + 1) & 1){
printf("No\n");
}
else{
printf("Yes\n");
}
}
else{
double res = 0;
for(int i = n; i >= 0; --i){
res = res * k + a[i]; }
if(res == 0){
printf("Yes\n");
}
else{
printf("No\n");
}
}
}
}
}

最新文章

  1. c#如何判断webbrowser已经加载完毕
  2. substr 与 substring 的区别
  3. struts2配置文件中Action中的各属性的含义
  4. [LintCode] Candy 分糖果问题
  5. 图解 &amp; 深入浅出Java初始化与清理:构造器必知必会
  6. UITextView 点return 隐藏键盘
  7. poj 1459 Power Network : 最大网络流 dinic算法实现
  8. ASP.NET母版页与内容页相对路径的问题
  9. windows下redis 开机自启动
  10. ​C语言数组作为函数参数
  11. Cognos 图表用图片取代”没有数据显示”
  12. Nmap的使用【转载】
  13. AFN
  14. Java基础---IO(三)--IO包中的其他类
  15. python 自动化之路
  16. 一句话的事儿,Head first 设计模式
  17. phpstorm 一个窗口打开多个项目
  18. SpringBoot工程+热部署进行远程调试
  19. Go 语言相关的优秀框架,库及软件列表
  20. 搭建ReactNative时的最普遍的错误—— &quot;:CFBundleIdentifier&quot;, Does Not Exist

热门文章

  1. JDBC整理
  2. 方括号在sqlserver中的作用
  3. SQlException 对象名无效
  4. 洛谷P1962 斐波那契数列(矩阵快速幂)
  5. SQLAlchemy tutorial
  6. linux系统管理-软件包管理
  7. 12、Camel: Content-Aware and Meta-path Augmented Metric Learning for Author Identification----作者识别
  8. 《Exception》第八次团队作业:Alpha冲刺(大结局)
  9. [BZOJ3438][洛谷P1361]小M的作物
  10. BZOJ 1176/2683 Mokia (三维偏序CDQ+树状数组)