标签:blog std bool ccf use namespace main pre pause
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int n;
int a[303];
int b[303];
bool flag=false;
void dfs(int k,int now,int pre,int pre1){//已经遍历到第k个了.pre表示前1个,pre1表示前两个
if(flag)
return;
if(k>n){
return;
}
if(k==n){
if((now+pre+pre1)/3!=a[k-2])
return;
else b[k-2]=pre;
if((now+pre)/2!=a[k-1])
return;
else {
b[k-1]=now;
flag=true;
return;
}
}else if(k==2){
if((now+pre)/2!=a[k-2])
return;
else b[k-2]=pre;
}else if(k!=1){
if((now+pre+pre1)/3!=a[k-2])
return;
else b[k-2]=pre;
}
for(int i=1;i<=298;i++){
dfs(k+1,i,now,pre);
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
dfs(0,0,0,0);
for(int i=0;i<n-1;i++){
cout<<b[i]<<" ";
}
cout<<b[n-1]<<endl;
//system("pause");
return 0;
}
标签:blog std bool ccf use namespace main pre pause
原文地址:https://www.cnblogs.com/GarrettWale/p/11428882.html