1. 程式人生 > >CF676E:The Last Fight Between Human and AI

CF676E:The Last Fight Between Human and AI

tdi sca color 每次 %d out 。。 mat scanf

人類和電腦在一個多項式上進行博弈,多項式的最高次項已知,一開始系數都不確定。電腦先開始操作,每次操作可以確定某次項的系數,這個系數可以是任意實數。給出一個博弈中間狀態,最後如果這個多項式被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

CF676E:The Last Fight Between Human and AI