Portal
Thinking of solving problems
Just started according to Yzy God Ben to the method of writing, is every time to calculate the calculated out, the result because too much food write hung. After the direct explosion of water.
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>using namespacestd;Const intmaxn= +;intn,a[maxn],cnt;Chars[4][MAXN];BOOLVis[maxn],flag;BOOLCheck () { for(Registerintj=n;j;j--){ if(a[s[1][j]-'A']<0|| a[s[3][j]-'A']<0|| a[s[2][j]-'A']<0)Continue; if((a[s[1][j]-'A']+a[s[2][j]-'A'])%n!=a[s[3][j]-'A'] && (a[s[1][j]-'A']+a[s[2][j]-'A']+1)%n!=a[s[3][j]-'A'])return false; } return true;}BOOLPD () {intPre=0; for(Registerintj=n;j;j--){ if((a[s[1][j]-'A']+a[s[2][j]-'A']+pre)%n!=a[s[3][j]-'A'])return false; Pre= (a[s[1][j]-'A']+a[s[2][j]-'A']+PRE)/N; } returnPre?false:true;}voidDfsintXintNow ) { if(now==4) {now=1; x--;if(x==0) {if(PD ()) flag=1;return;}} if(a[s[now][x]-'A']>=0) {DFS (x,now+1);return;} for(Registerinti=n-1; i>=0; i--){ if(Vis[i])Continue; Vis[i]=1; a[s[now][x]-'A']=i; if(!check ()) {vis[i]=0; a[s[now][x]-'A']=-1;Continue;} DFS (X,now+1);if(flag)return; vis[i]=0; a[s[now][x]-'A']=-1; }}intMain () {memset (A,-1,sizeof(a)); scanf ("%d%s%s%s", &n,s[1]+1, s[2]+1, s[3]+1); DFS (N,1); for(RegisterintI=0; i<n;i++) printf ("%d", A[i]); return 0;}/*4BADCCBDADCCC*/
View Code
Lugou P1092 Insect Food Calculation