您的位置:首页 > 大数据 > 人工智能

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],他这里推导的很完整,不过这个方法只能算是黑科技。

//
//  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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: