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

作者: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. JAVA实现将GeoHash转化为相应的经纬度坐标

    转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/50568428 http://www.llwjy.com/blogdetail/f ...

  2. 畅通project续HDU杭电1874【dijkstra算法 || SPFA】

    http://acm.hdu.edu.cn/showproblem.php?pid=1874 Problem Description 某省自从实行了非常多年的畅通project计划后.最终修建了非常多 ...

  3. UI组件之AdapterView及其子类(五)ListView组件和ListActivity

    ListView组件是一个显示组件,继承AdapterView基类,前面已经介绍了分别使用ArrayAdapter,SimpleAdapter,扩展BaseAdapter来为LisView提供列表项h ...

  4. Linux以下基于TCP多线程聊天室(client)

    不怎么会弄这个博客的排版,就直接将代码附上: 主要是使用多线程去等待接受数据和发送数据.以下是client的代码: tcpsed.h文件 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...

  5. FFMpeg在Windows下搭建开发环境【转】

    本文转载自:http://blog.csdn.net/wootengxjj/article/details/51758621 版权声明:本文为博主原创文章,未经博主允许不得转载. FFmpeg 是一个 ...

  6. How do I UPDATE from a SELECT in SQL Server?

    方法1 https://stackoverflow.com/questions/2334712/how-do-i-update-from-a-select-in-sql-server UPDATE T ...

  7. 云:VMware

    ylbtech-云:VMware VMware总部位于美国加州帕洛阿尔托 ,是全球云基础架构和移动商务解决方案厂商,提供基于VMware的解决方案,企业通过数据中心改造和公有云整合业务,借助企业安全转 ...

  8. 两个NSMutableDictionary合并成一个NSMutableDictionary

    解决方案: NSMutableDictionary *targetMutableDictionary = [mutableDictionary1 copy]; [targetMutableDictio ...

  9. Spark任务调度

    不多说,直接上干货! Spark任务调度 DAGScheduler 构建Stage—碰到shuffle就split 记录哪个RDD 或者Stage 输出被物化 重新提交shuffle 输出丢失的sta ...

  10. for循环的写法及优化

    最近这几天在研究浏览器性能的时候发现了一些小知识,在此做一总结: 其中经常用到的for循环有:正常的for循环,for in循环,for of循环等,但是对于正常的for循环可以做一下优化,使得其在执 ...