Codeforces 676E The Last Fight Between Human and AI 规律
2016-05-30 22:52
579 查看
链接
题意
给一个多项式,有些系数不确定。人和机器轮流填系数,系数可以是任何数,问是否能使得最后的多项式整除 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"); } } } } }
相关文章推荐
- DLL入口函数DllMain
- MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainC
- Leetcode 172. Factorial Trailing Zeroes
- LLVM example for main
- Scala中特质trait与抽象类abstract的区别
- 在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan" 可以让界面不被弹出的键盘挤上去。
- RAID磁盘阵列
- Easy-题目41:219. Contains Duplicate II
- Easy-题目32:172. Factorial Trailing Zeroes
- Only Link: Inheritance and the prototype chain
- Easy-题目18:70. Climbing Stairs
- Easy-题目10:217. Contains Duplicate
- ping www.baidu.com 不通 开启DNS
- xenomai-GNU/Linux上的RTOS模拟架构实现
- Make things beautiful again !
- Make things beautiful again !
- Make things beautiful again !
- Make things beautiful again !
- codeforces 667A A. Pouring Rain(水题)
- http://www.mamicode.com/info-detail-1150460.html