- 虫食算
- 2016-10-26 22:28:29 @
全WA
```
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int n,X[5][30],let[30],vis[30]={0};
bool check(){
int i,j,tmp[5][30];
for(i=1;i<=3;i++){
for(j=0;j<n;j++){
tmp[i][j]=let[X[i][j]];
}
}
int k=0,re[30]={0};
for(i=n-1;i>=0;i--){
re[i]=tmp[1][i]+tmp[2][i]+k;
k=re[i]/n;
re[i]=re[i]%n;
}
if(memcmp(re,tmp[3],sizeof(re))==0) return true;
else return false;
}
void dfs(int step){
int i;
if(step==n){
if(check()){
for(i=0;i<n-1;i++){
printf("%d ",let[i]);
}
printf("%d",let[n-1]);
exit(0);
}
}
for(i=4;i>=0;i--){
if(!vis[i]){
let[step]=i;
vis[i]=1;
dfs(step+1);
vis[i]=0;
}
}
}
int main(){
//freopen("in.txt","r",stdin);
int i,j;
char ch;
scanf("%d",&n);
ch=getchar();
for(i=1;i<=3;i++){
for(j=0;j<n;j++){
scanf("%c",&ch);
X[i][j]=ch-'A';
}
ch=getchar();
}
dfs(0);
return 0;
}
```
3 条评论
-
贱人在我右边 LV 9 @ 2016-12-17 09:44:46
stupid
-
2016-12-17 09:44:39@
yes!
-
2016-11-16 20:44:03@
I did think that you are a foreigner and don't know Chinese. 但是你懂,你tm非用英文干啥?
- 1