Codeforces Round #354 (Div. 2) E - The Last Fight Between Human and AI
来源:互联网 发布:甘肃启航网络待遇 编辑:程序博客网 时间:2024/05/21 17:34
转自别人的题解:(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+6;#define LL long long#define INF 0x3f3f3f3fint 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)puts("Yes");elseputs("No");}else if (a[0])puts("No");elseputs("Yes");}else{if(cnt < n){if(n%2==1)puts("No");elseputs("Yes");}else{ LL 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"));}}}
0 0
- Codeforces Round #354 (Div. 2) E - The Last Fight Between Human and AI
- 【Codeforces Round 354 (Div 2)E】【数学 多项式除法 讨论】The Last Fight Between Human and AI 多项式除以x-k是否值整除
- [Codeforces Round #354 DIV2E (CF676E)] The Last Fight Between Human and AI
- [数学] codeforces 676E. The Last Fight Between Human and AI
- Codeforces 676E The Last Fight Between Human and AI (数论)
- Codeforces Round #278 (Div. 2) 488C.Fight the Monster
- Codeforces Round #278 (Div. 2) C. Fight the Monster(暴力)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) E. The Holmes Children
- Codeforces Round #435 (Div. 2) E. Mahmoud and Ehab and the function
- Codeforces Round #435 (Div. 2) E. Mahmoud and Ehab and the function
- Codeforces Round #278 (Div. 2) C. Fight the Monster 二分+枚举
- Codeforces Round #177 (Div. 2)---E. Polo the Penguin and XOR operation(贪心)
- Codeforces Round #333 (Div. 2) E. Kleofáš and the n-thlon (概率dp)
- Codeforces Round #167 (Div. 2) 272E Dima and Horses
- Codeforces Round #206 (Div. 2) E. Vasya and Beautiful Arrays
- Codeforces Round #208 (Div. 2)E. Dima and Kicks
- Codeforces Round #199 (Div. 2) E. Xenia and Tree
- Codeforces Round #224 (Div. 2) E.Ksenia and Combinatorics
- Mysql 数据备份与还原
- 剑指Offer:二叉树的镜像
- hdu2795(线段树,节点更新)
- 第一次只出现一次的字符
- getSerializableExtra用法体会
- Codeforces Round #354 (Div. 2) E - The Last Fight Between Human and AI
- 我和我的小伙伴们
- Mysql 插入、更新与删除数据
- Android 打印输出16进制数据
- 从0到1(上)
- jdbc连接数据库
- safari地址栏无法使用百度搜索
- JavaScript五子棋
- 页面跳转(pop返回多个ViewController)