2016年第七届蓝桥杯C/C++程序设计本科B组决赛

时间:2022-12-01 21:48:11

2.答案300

刁丝卫代码,比赛时long long写成int,结果成了263。。。一等擦肩而过。。。

#include <iostream>
#include <fstream>
#include <cstring>
#define LL long long
using namespace std;
bool mark[];
LL res[],sum=;
bool tmpmark[];
bool judge(LL x){
memset(tmpmark,,sizeof(tmpmark));
if(x==){
if(mark[] == )
return false;
return true;
}
while(x!=){
if(mark[x%] || tmpmark[x%])
return false;
tmpmark[x%] = ;
x/=;
}
return true;
} int update(LL x,int coun){
if(x==){
mark[x] = ;
coun++;
return coun;
}
while(x!=){
mark[x%] = ;
x/=;
coun++;
}
return coun;
} void reupdate(LL x){
if(x==){
mark[x] = ;
return ;
}
while(x!=){
mark[x%] = ;
x/=;
}
} void dfs(int coun,int rescoun,LL last){
if(coun == ){
for(int i=;i<rescoun;i++)
cout<<res[i]<<' ';
cout<<">>>"<<sum<<endl;
sum++;
return ;
}
for(LL i=last;i<;i++){
if(judge(i*i)){
int tmpcoun = update(i*i,coun);
res[rescoun] = i*i;
dfs(tmpcoun,rescoun+,i+);
reupdate(i*i);
}
}
}
int main (){
memset(mark,,sizeof());
dfs(,,);
cout<<sum;
return ;
}