2016年第七届蓝桥杯C/C++程序设计本科B组决赛
2016-06-01 18:29
435 查看
2.答案300
刁丝卫代码,比赛时long long写成int,结果成了263。。。一等擦肩而过。。。
View Code
刁丝卫代码,比赛时long long写成int,结果成了263。。。一等擦肩而过。。。
#include <iostream> #include <fstream> #include <cstring> #define LL long long using namespace std; bool mark[100]; LL res[100],sum=0; bool tmpmark[10]; bool judge(LL x){ memset(tmpmark,0,sizeof(tmpmark)); if(x==0){ if(mark[0] == 1) return false; return true; } while(x!=0){ if(mark[x%10] || tmpmark[x%10]) return false; tmpmark[x%10] = 1; x/=10; } return true; } int update(LL x,int coun){ if(x==0){ mark[x] = 1; coun++; return coun; } while(x!=0){ mark[x%10] = 1; x/=10; coun++; } return coun; } void reupdate(LL x){ if(x==0){ mark[x] = 0; return ; } while(x!=0){ mark[x%10] = 0; x/=10; } } void dfs(int coun,int rescoun,LL last){ if(coun == 10){ for(int i=0;i<rescoun;i++) cout<<res[i]<<' '; cout<<">>>"<<sum<<endl; sum++; return ; } for(LL i=last;i<100000;i++){ if(judge(i*i)){ int tmpcoun = update(i*i,coun); res[rescoun] = i*i; dfs(tmpcoun,rescoun+1,i+1); reupdate(i*i); } } } int main (){ memset(mark,0,sizeof(0)); dfs(0,0,0); cout<<sum; return 0; }
View Code
相关文章推荐
- (C++)虚析构函数
- 第十三周【项目 1分数类中的运算符重载】
- C++中的头文件和源文件的学习
- C++ 初始化列表
- cpp 4个类型转换
- C/C++中static关键字详解
- C++的头文件和实现文件分别写什么
- 第10章 C语言及程序设计提高例程-37 操作字符串数组
- c语言实现的的map
- C++多继承中虚基类
- 第13周项目2--动物这样叫(2)
- 矩阵翻转
- C++之中this指针与类的六个默认函数小结
- C语言for循环的执行顺序
- 第10周 C语言及程序设计提高例程-36 多维数组作函数参数
- 二叉树的C++模板类头文件源代码实现
- C/C++中关键字extren作用总结
- C++ typedef用法小结 (※不能不看※)
- C++11
- C++拷贝欧构造函数