Codeforces 676E The Last Fight Between Human and AI (数论)
2017-01-18 16:12
435 查看
题意:
给定一个参数不确定的多项式,电脑和人类轮流确定系数的大小,可以使任意实数,使得这个多项式能够除以x-k,判断如果人类选择最优的方法,是否可以胜利。
解法:
这题要分类讨论,如果k=0的话,只要a[0]=0,那么就可以整除,所以我么你只需要判断a[0]是否已经被赋值且是否为0,这个好判断。
然后是k不等于0时,那么就有两种情况,一种是所有的系数都被赋值了,判断k是否是这个多项式的根就好了,如果有没有赋值的,因为系数可以使任意数字,所以不到最后一个,结果都会改变,也就是说最后一个人可以决定输赢。但是对前一种情况,因为数字太大,无法直接来严重,所以我们需要用线性代数推导一下,具体过程就不在这里说了,给一个链接[戳这里][1],他这里推导的很完整,不过这个方法只能算是黑科技。
给定一个参数不确定的多项式,电脑和人类轮流确定系数的大小,可以使任意实数,使得这个多项式能够除以x-k,判断如果人类选择最优的方法,是否可以胜利。
解法:
这题要分类讨论,如果k=0的话,只要a[0]=0,那么就可以整除,所以我么你只需要判断a[0]是否已经被赋值且是否为0,这个好判断。
然后是k不等于0时,那么就有两种情况,一种是所有的系数都被赋值了,判断k是否是这个多项式的根就好了,如果有没有赋值的,因为系数可以使任意数字,所以不到最后一个,结果都会改变,也就是说最后一个人可以决定输赢。但是对前一种情况,因为数字太大,无法直接来严重,所以我们需要用线性代数推导一下,具体过程就不在这里说了,给一个链接[戳这里][1],他这里推导的很完整,不过这个方法只能算是黑科技。
// // Created by CQU_CST_WuErli // Copyright (c) 2016 CQU_CST_WuErli. All rights reserved. // //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <string> #include <vector> #include <map> #include <queue> #include <stack> #include <set> #include <algorithm> #include <sstream> #define CLR(x) memset(x,0,sizeof(x)) #define OFF(x) memset(x,-1,sizeof(x)) #define MEM(x,a) memset((x),(a),sizeof(x)) #define BUG cout << "I am here" << endl #define lookln(x) cout << #x << "=" << x << endl #define SI(a) scanf("%d", &a) #define SII(a,b) scanf("%d%d", &a, &b) #define SIII(a,b,c) scanf("%d%d%d", &a, &b, &c) const int INF_INT=0x3f3f3f3f; const long long INF_LL=0x7f7f7f7f; const long long MOD=4000000017; const double eps=1e-10; const double pi=acos(-1); typedef long long ll; using namespace std; ll n, k; ll a[100010]; int main(int argc, char const *argv[]) { #ifdef LOCAL freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin); // freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout); #endif while (cin >> n >> k) { string s; int op = 0; for (int i = 0; i <= n; i++) { cin >> s; if (s[0] == '?') a[i] = INF_INT; else { op++; ll flag = 1LL; int cnt = 0; if (s[cnt] == '-') flag = -1, cnt++; int tmp = 0; while (cnt < s.size()) { tmp = tmp * 10 + s[cnt++] - '0'; } a[i] = tmp * flag; } } if (k == 0) { if (a[0] == 0) puts("Yes"); else if (a[0] >= INF_INT) puts(op % 2 == 1 ? "Yes" : "No"); else puts("No"); } else { if (op < n + 1) puts((n + 1) % 2 == 1 ? "No" : "Yes"); else { ll tmp = 0; for (int i = n; i >= 1; i--) { tmp = tmp * k + a[i]; tmp %= MOD; } if (tmp % MOD * k * -1 % MOD == a[0] % MOD) puts("Yes"); else puts("No"); } } } return 0; }
相关文章推荐
- CodeForces 584D - Dima and Lisa(数论)
- Codeforces 584 A. Olesya and Rodion 数论+找规律(构造)
- CodeForces 3107 ODDDIV - Odd Numbers of Divisors(数论)
- CodeForces 7C Line Exgcd(数论)
- codeforces 487C C. Prefix Product Sequence(数论+构造)
- CodeForces 548E Mike and Foam (容斥+数论)
- CodeForces - 376C Divisible by Seven(数论:同余定理)(找规律)
- CodeForces - 58B Coins(数论)
- codeforces 807C Success Rate 数论
- CodeForces 346A Alice and Bob(数论)
- codeforces 66 D. Petya and His Friends(数论)
- Codeforces 757B Bash's Big Day 【数论】
- Codeforces 236C LCM Challenge 数论(基础题)
- Codeforces 412E E-mail Addresses(数论)
- codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)(两种方法)
- codeforces 337E E. Divisor Tree(数论+贪心)
- CodeForces - 376C Divisible by Seven(数论:同余定理)(找规律)
- Codeforces 837E Vasya's Function - 数论
- CodeForces - 359C Prime Number(数论)
- codeforces 27E - Number With The Given Amount Of Divisors (数论 dfs)