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

作者: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. 用户体验之如何优化你的APP

    用户体验,速度为王,来几个优化APP“速度”的建议. 1.后台执行 毋庸多言,已是通常做法. 一般在执行下载任务时让其在后台运营,让用户有精力去做别的事情. 后端加载 2.提前显示 客户端与WEB的数 ...

  2. Tcl学习之--表达式

    l 数值操作数 表达式的操作数一般是整数或实数.整数可能是十进制.二进制,八进制或十六进制. 比方以下同一个整数 335               --> 十进制 0o517         ...

  3. codeforces 571A--Lengthening Sticks(组合+容斥)

    A. Lengthening Sticks time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. iOS项目开发实战——制作视图的缩放动画

    视图的大小应该是随时可控的.今天我们就来实现对一个View的缩放动画.该动画的实现与位移动画,透明度动画稍有不同. 详细实现例如以下: import UIKit class ScaleViewCont ...

  5. PHP分页组件:Paginator

    安装 composer require "jasongrimes/paginator:~1.0" 使用 <?php require '../vendor/autoload.p ...

  6. BZOJ4819: [Sdoi2017]新生舞会(01分数规划)

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1029  Solved: 528[Submit][Status][Discuss] Descripti ...

  7. 「JavaSE 重新出发」05.03 反射

    能够分析类能力的程序称为反射(reflection). 反射库(reflection library)提供了一个非常丰富且精心设计的工具集,以便编写能够动态操纵 Java 代码的程序. 反射机制可以用 ...

  8. hdu 1072 广搜(逃离爆炸迷宫)

    题意: 在n×m的地图上,0表示墙,1表示空地,2表示人,3表示目的地,4表示有定时炸弹重启器.定时炸弹的时间是6,人走一步所需要的时间是1.每次可以上.下.左.右移动一格.当人走到4时如果炸弹的时间 ...

  9. ES6 Symbol类型 附带:Proxy和Set

    七种数据类型 ·Symbol ·undefined ·null ·Boolean ·String ·Number ·Object let a = Symbol('this is a symbol'); ...

  10. linux防火墙查看状态firewall、iptable

    一.iptables防火墙1.基本操作 # 查看防火墙状态 service iptables status # 停止防火墙 service iptables stop # 启动防火墙 service ...