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

作者: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;
}

uva725_一道水题(优化到了29ms)的更多相关文章

  1. ny525 一道水题

    一道水题时间限制:1000 ms  |  内存限制:65535 KB 难度:2描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他吗? ...

  2. NYOJ-525一道水题思路及详解

    一道水题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他 ...

  3. LibreOJ #6165. 一道水题

    二次联通门 : LibreOJ #6165. 一道水题 /* LibreOJ #6165. 一道水题 欧拉线性筛 其实题意就是求区间[1, n]所有数的最小公倍数 那么答案就是所有质因子最大幂次的乘积 ...

  4. [ Luogu 4626 ] 一道水题 II

    \(\\\) \(Description\) 求一个能被\([1,n]\) 内所有数整除的最小数字,并对 \(100000007\) 取模 \(N\in [1,10^8]\) \(\\\) \(Sol ...

  5. [Luogu] P4626 一道水题 II

    ---恢复内容开始--- 题目描述 一天,szb 在上学的路上遇到了灰太狼. 灰太狼:帮我们做出这道题就放了你. szb:什么题? 灰太狼:求一个能被 [1,n] 内所有数整除的最小数字,并对 100 ...

  6. 2018焦作网络赛 - Poor God Water 一道水题的教训

    本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...

  7. 牛客小白月赛9H论如何出一道水题(两个连续自然数互质)

    题面 记录一下...连续得两个自然数互质,这题再特判一下1的情况 #include<bits/stdc++.h> using namespace std; int main() { lon ...

  8. UPC OJ 一道水题 STL

    Problem C: 字符串游戏 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 10  Solved: 3 [Submit][Status][Web ...

  9. 又是一道水题 hdu背包

    Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...

随机推荐

  1. Windows平台编译openssl-0.9.8k库(32位、64位)

    近期工作中使用到了openssl的win64位资料,所以进行前期调研,汇总结果例如以下: [注意]openssl代码所在文件夹中不要带中文,否则"nmake -f ms\ntdll.mak ...

  2. (素数求解)I - Dirichlet&#39;s Theorem on Arithmetic Progressions(1.5.5)

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...

  3. 【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)

    [POJ 2942]Knights of the Round Table(双联通分量+染色判奇环) Time Limit: 7000MS   Memory Limit: 65536K Total Su ...

  4. oracle RAC 11g sqlload 生产表导入数据(ORA-12899)

    背景:由于即将来临的双十一,业务部门(我司是做京东,天猫的短信服务),短信入库慢,需要DBA把数据库sqlload进数据库. 表结构如下: MRS VARCHAR2(100), STATUS VARC ...

  5. node.js流复制文件

    转自:http://segmentfault.com/a/1190000000519006 nodejs的fs模块并没有提供一个copy的方法,但我们可以很容易的实现一个,比如: var source ...

  6. pgpool中的配置参数的定义

    /* * configuration parameters */typedef struct {    char *listen_addresses;            /* hostnames/ ...

  7. Win10 UI入门 pivot multiable DataTemplate

    this is a dynamic pivot with sliderable navigation and multiableDatatemplate Control 看了 alexis 大哥的pi ...

  8. zabbix-server端监控MySQL服务

    Zabbix 监控MySQL数据库 为server.zabbix,com 添加服务模块 创建MySQL服务图形 Server.zabbix.com 服务器操作 [root@server ~]# cd ...

  9. luogu P3387 【模板】缩点_拓扑排序

    还是很好些的. Code: #include <stack> #include <cstdio> #include <algorithm> #include < ...

  10. input上传文件获取文件后缀名+select通过text选中option

    1.input获取后缀名 var fileName = $("input[type='file']").val();//获取上传的文件(单个) var extName = file ...