紫书P182

直接枚举 0~9 的全排列会超时,枚举fghij就可以了,计算出 abcde ,这里有一个新的函数,也可以不用咯,把每一位数据提取出来,while循环可以做到,这里的新的函数是,sprintf(buf,"%5d%5d",abcde,fghij); 格式化提取,把abcde,fghij每一位提取到字符串buf中,不足5位的补0。然后看每一个位是否都有。都有就是一个0~9的全排列。

/*#include <stdio.h>
#include <algorithm> using namespace std; int main()
{
int n;
int a[10] = {0,1,2,3,4,5,6,7,8,9};
while(scanf("%d",&n),n) { bool flag = false;
do { int s = 0;
for(int i=0;i<5;i++) {
s = s*10 + a[i];
}
int t = 0;
for(int i=5;i<10;i++) {
t = t*10 + a[i];
}
if(s%t==0&&s/t==n) {
flag = 1;
printf("%d%d%d%d%d / %d%d%d%d%d = %d\n",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],n);
} }while(next_permutation(a,a+10)); if(!flag)
printf("There are no solutions for %d.\n",n); } return 0;
}
*/ #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int main() { //freopen("in.txt","r",stdin);
int n;
int kase = ;
char buf[];
while(scanf("%d",&n),n) { if(kase++)
printf("\n");
int cnt = ;
for(int fghij = ;;fghij++) {
int abcde = fghij*n;
sprintf(buf,"%05d%05d",abcde,fghij);
if(strlen(buf)>) break;
sort(buf,buf+);
bool ok = true;
for(int i=;i<;i++) {
if(buf[i]!=''+i) ok = false;
} if(ok) {
cnt++;
printf("%05d / %05d = %d\n",abcde,fghij,n);
} }
if(!cnt)
printf("There are no solutions for %d.\n",n); } return ;
}

Uva 725 除法的更多相关文章

  1. uva 725 Division(除法)暴力法!

    uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  2. 除法(Division ,UVA 725)-ACM集训

    参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...

  3. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

  4. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  5. UVA.725 Division (暴力)

    UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...

  6. UVA 725 UVA 10976 简单枚举

    UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...

  7. 暴力求解——除法 Division,UVa 725

    Description Write a program that finds and displays all pairs of 5-digit numbers that between them u ...

  8. Uva 725 Division

    0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...

  9. uva 725 division(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A

随机推荐

  1. PostgreSQL simple select(group by and insert into ...select)

    warehouse_db=# create table student(number int primary key,name varchar(20),age int);CREATE TABLEwar ...

  2. poj: 3006

    简单题 #include <iostream> #include <stdio.h> #include <string> #include <stack> ...

  3. PHP与jquery前后台交互的小程序

    1 <!DOCTYPE HTML> <html> <head> <meta charset = "utf-8"> <scrip ...

  4. 夺命雷公狗---DEDECMS----15dedecms首页栏目列表页导航部分完成

    我们在点击导航页面的连接时候我们需要我们的连接跳到指定的模版页面,而不是随便跳到一个指定的A连接标签: 所以我们首先要将前端给我们的栏目列表模版拷贝到目录下,然后就可以创建栏目列表页面了,但是名字我们 ...

  5. For 循环嵌套 0309

                                                                                                     For ...

  6. SQL 中逻辑运算符的优先级

    三个逻辑运算符: NOT AND OR 它们的优先级依次降低(跟多数的高级程序设计语言的优先级顺序一致) 如果要提升某部分的优先级,可以使用半角括号实现 (这点也跟多数高级程序设计语言一致)

  7. 如何通过类找到对应的jar包

    ctrl+shift+T 然后输入对应类  

  8. php ssh2 scp问题解决

    <?php$connection = ssh2_connect('192.168.1.XX', 22);$res=ssh2_auth_password($connection, 'root', ...

  9. 2016年最好的15个Web设计和开发工具

    1.ai2html ai2html是适用于Adobe Illustrator的开源脚本,可以转换Illustrator文件为html和css. 官方网站:http://ai2html.org/ 2.A ...

  10. Linux下通过crontab及expect实现自动化处理

    版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 目标 为实现每天定时从其他服务器上复制文件到本地,需要使用crontab建立定时任务,并通过scp进行Linux之间的文件复制. ...