///////////////////////////////////////////////////////////////////////////////////////////////////////

作者:tt2767

声明:本文遵循下面协议自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0

查看本文更新与讨论请点击:http://blog.csdn.net/tt2767

链接被删请百度: CSDN tt2767

///////////////////////////////////////////////////////////////////////////////////////////////////////


能够用 n * fghij 去枚举 abcde 判重就可以

由于fghij 可能自身反复较多。能够先判掉。节省时间;

假设不写成函数的形式还能更快一些。由于第二次判段中x,已经推断过了。

书中的做法是把两个数字化成字符串去。排序后推断用时

123ms

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//////////////////////
#include<iostream>
#include<algorithm>
#include<string>
#include <iterator>
#include<sstream>
#include<functional>
#include<numeric>
///////////////////////
#include<vector>
#include<map>
#include <stack>
#include<queue>
#include<set>
#include <bitset>
#include <list>
using namespace std;
#define lch(x) ((x) << 1)
#define rch(x) ((x)<<1|1)
#define dad(x) ((x)>>1)
#define lowbit(x) ((x)&(-x))
typedef long long int LL;
const int INF = ~0U>>1;
const double eps = 1e-6;
const long double PI = acos(0.0) * 2.0;
//const int N = 10 + ;
const int MAX = 98765,MIN = 1234;
bool check(int x , int l1,int y ,int l2);
int main()
{
//ios::sync_with_stdio(false);
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
freopen("out3.txt", "w", stdout);
#endif
int n;
int tot = 0;
while(scanf("%d",&n)==1&& n)
{
if(tot++) puts("");
bool flag=1;
for(int i = MIN ; i<= MAX ; i++)
{
int l1 = log10(i)+1;
if(!check(i,l1,-1,-1)) continue;
int j = i*n;
int l2 = log10(j)+1;
if(j>MAX) break;
if(!check(i,l1,j,l2)) continue;
flag = 0;
printf("%05d / %05d = %d\n",j,i,n);
}
if(flag)
printf("There are no solutions for %d.\n", n);
}
return 0;
} bool check(int x , int l1,int y ,int l2)
{
bool re[10];
memset(re,0,sizeof(re));
if(l1==4&&l2==4) return 0;
if(l1==4 || l2==4) re[0]=1;
while(x)
{
if(re[x%10]) return 0;
re[x%10] = 1;
x/=10;
}
if(y != -1)
while(y)
{
if(re[y%10]) return 0;
re[y%10] = 1;
y/=10;
}
return 1;
}

最新文章

  1. 深入浅出 妙用Javascript中apply、call、bind
  2. Linux环境变量配置
  3. Java 日志性能优化
  4. python 循环语句的else语句用法,当循环条件变为假,切不是通过breakbreak终止的时候,就会执行这个else语句。
  5. MyEclipse8.5破解方法
  6. [51单片机] TFT2.4彩屏2 [32*32文字显示]
  7. for( unsigned int i=heapSize/2-1; i>=0; --i)
  8. Java 8 开发顶级技巧
  9. Lodash Filter
  10. [Java]知乎下巴第0集:让我们一起来做一个知乎爬虫吧哦耶【转】
  11. MySQL学习笔记(三)&mdash;索引
  12. 同时安装python2和python3
  13. C语言获取系统时间的函数
  14. JS中事件绑定函数,事件捕获,事件冒泡
  15. 使用拦截器对前端传入的字符串进行trim操作
  16. redcontrol for SL 中文化及样式选择
  17. [LeetCode] 872. Leaf-Similar Trees_Easy tag: DFS
  18. 前端之css操作2
  19. linux 知识点
  20. Window 下好用的同步备份工具(来自微软)SyncToy

热门文章

  1. Linux内核project导论——网络:Netfilter概览
  2. python2.7编码与解码
  3. DOM基础----DOM(一)
  4. UVALive 3027 Corporative Network 带权并查集
  5. COGS 2580. [HZOI 2015]偏序 II
  6. ubuntu下Chrome谷歌浏览器部分网站图片显示不正常的解决方法
  7. 软件测试作业-selenium
  8. React router内是如何做到监听history改变的
  9. node.js连接数据库登录注册,修改用户(页面的ajax请求)
  10. 快速搭建golden gate环境