zoukankan      html  css  js  c++  java
  • Codeforces 676E The Last Fight Between Human and AI 规律

    链接

    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
    ");
                }
                else if(a[0] == INF){
                    if((n + 1 - unk) & 1){
                        printf("Yes
    ");
                    }
                    else{
                        printf("No
    ");
                    }
                }
                else{
                    printf("No
    ");
                }
            }
            else{
                if(unk > 0){
                    if((n + 1) & 1){
                        printf("No
    ");
                    }
                    else{
                        printf("Yes
    ");
                    }
                }
                else{
                    double res = 0;
                    for(int i = n; i >= 0; --i){
                        res = res * k + a[i];
    
                    }
                    if(res == 0){
                        printf("Yes
    ");
                    }
                    else{
                        printf("No
    ");
                    }
                }
            }
        }
    }
    
  • 相关阅读:
    Nginx安装详细指南
    git 常用命令
    oracle server config
    CentOS6.5下安装oracle11gR2
    oracle query
    oracle function
    oracle note
    正则表达
    DOM&BOM的起源、方法、内容、应用
    sticky
  • 原文地址:https://www.cnblogs.com/macinchang/p/5544233.html
Copyright © 2011-2022 走看看