CF676E:The Last Fight Between Human and AI

人类和电脑在一个多项式上进行博弈,多项式的最高次项已知,一开始系数都不确定。电脑先开始操作,每次操作可以确定某次项的系数,这个系数可以是任意实数。给出一个博弈中间状态,最后如果这个多项式被x-K整除就算人类赢,问人类是否有可能赢。n<=1e5,K和所有给出的系数的绝对值在1e4内,不确定的系数用?表示。

这个读入有点坑爹。。。

要使,做一下除法,余数大概长这个样子

问题即有没有可能使L为0。

(一)K=0时,决胜关键就在a0,如果a0确定了并且不为0那就完了,如果a0没确定,看轮到谁,轮到人类赢,轮到电脑输。

(二)K≠0时

(1)如果有系数未确定,看最后一步是谁走,如果是人类走,则最后相当于解一个一元一次方程,由于k不为0因此一定有解,如果电脑走则一定输。

(2)如果系数都确定了,就要检验这个式子是否为0,由于次数太高无法计算,因此取几个模数检验一下模完是否都是0,用秦九韶计算。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 #include<algorithm>
 5 //#include<assert.h>
 6 #include<math.h>
 7 #include<iostream>
 8 using namespace std;
 9 
10 int n,k;
11 #define maxn 100011
12 #define LL long long
13 const int mod[]={10007,1000007,1000000007,19260817,999911659};
14 int a[maxn];bool ok[maxn];char s[20];
15 int main()
16 {
17     scanf("%d%d",&n,&k);
18     int cnt=0;
19     memset(ok,0,sizeof(ok));
20     for (int i=0;i<=n;i++)
21     {
22         scanf("%s",s);
23         if (s[0]=='?') cnt++,ok[i]=1;
24         else
25         {
26             int t=1;if (s[0]=='-') t=-1;
27             int tmp=0;for (int j=(s[0]=='-');j<strlen(s);j++) tmp=tmp*10+s[j]-'0';
28             a[i]=tmp*t;
29         }
30     }
31     bool ans=0;
32     if (k==0)
33     {
34         if (ok[0])
35         {
36             if ((n+1-cnt)&1) ans=1;
37             else ans=0;
38         }
39         else if (a[0]==0) ans=1;else ans=0;
40     }
41     else
42     {
43         if (cnt)
44         {
45             if (n&1) ans=1;
46             else ans=0;
47         }
48         else
49         {
50             bool flag=1;
51             for (int j=0;j<5;j++)
52             {
53                 LL ans=0;
54                 for (int i=n;i>=0;i--)
55                 {
56 //                    cout<<ans<<endl;
57                     ans=(ans*k+a[i])%mod[j];
58                 }
59 //                cout<<ans<<endl;
60                 if (ans) flag=0;
61             }
62             if (flag) ans=1;
63             else ans=0;
64         }
65     }
66     printf(ans?"Yes\n":"No\n");
67     return 0;
68 }
View Code

 

posted @ 2017-10-13 07:05  Blue233333  阅读(261)  评论(0编辑  收藏  举报