Uva 725 除法
紫书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 除法的更多相关文章
- uva 725 Division(除法)暴力法!
uva 725 Division(除法) A - 暴力求解 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- 除法(Division ,UVA 725)-ACM集训
参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- UVA 725 UVA 10976 简单枚举
UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...
- 暴力求解——除法 Division,UVa 725
Description Write a program that finds and displays all pairs of 5-digit numbers that between them u ...
- Uva 725 Division
0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...
- uva 725 division(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A
随机推荐
- Lintcode: Rehashing
The size of the hash table is not determinate at the very beginning. If the total size of keys is to ...
- 关于centos更新后virtualbox无法使用的问题
http://blog.csdn.net/zgglj/article/details/50325675
- php文件上传参数设置
php默认的 上传文件大小是2M,要上传超过此大小的文件,需要设置php和apache的一些参数,具体参考如下: 1.file_uploads:是否允许通过HTTP上传文件的开关,默认为ON就是开 2 ...
- C++之: CDib类
头文件Cdib.h 源文件Cdib.cpp
- android 项目学习随笔七(ViewPagerIndicator与ViewPager)
1.ViewPagerIndicator https://github.com/JakeWharton/ViewPagerIndicator package com.viewpagerindicato ...
- owner window 和 parent window 有什么区别?
1.Pop-up窗口: 一个弹出窗口是必须具有WS_POPUP属性的窗口,弹出窗口只能是一个Top-Level窗口,不能是子窗口,弹出窗口多用于对话框和消 ...
- 161018、springMVC中普通类获取注解service方法
1.新建一个类SpringBeanFactoryUtils 实现 ApplicationContextAware package com.loiot.baqi.utils; import org.sp ...
- scala简单的文件操作
1.scala写入文件操作 package com.test import java.io.File import java.io.PrintWriter /** * scala文件写入 */ obj ...
- ubuntu硬件配置查看命令
主板:sudo dmidecode |grep -A16 "System Information$"
- DE1-SOC开发板上搭建NIOS II处理器运行UCOS II
DE1-SOC开发板上搭建NIOS II处理器运行UCOS II 今天在DE1-SOC的开发板上搭建NIOS II软核运行了UCOS II,整个开发过程比较繁琐,稍微有一步做的不对,就会导致整个过 ...