uva 725 DIVISION (暴力枚举)
我的56MS
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
using namespace std; #define MEM(a,v) memset (a,v,sizeof(a))
// a for address, v for value #define max(x,y) ((x)>(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y)) #define debug printf("!\n") int num[];
bool visited[]; bool check(int a,int b)
{
MEM(visited,false); int j; for(j = ;j>=;j--)
{
int tmp = a%;
num[j] = tmp;
a/=;
}
for(j = ;j>=;j--)
{
int tmp = b%;
num[j] = tmp;
b/=;
} for(j = ;j<=;j++)
{
if(visited[num[j]])
return false;
visited[num[j]] = true;
}
return true; } int main()
{
int i,n,j,k,T=;
while(~scanf("%d",&n) && n)
{
if(T++)
printf("\n");
bool find = false;
for(i = ;i<=;i++)
{
if(i%n==)
{
int m = i/n;
if(check(i,m))
{
find =true;
for(j = ;j<=;j++)
printf("%d",num[j]);
printf(" / ");
for(j = ;j<=;j++)
printf("%d",num[j]);
printf(" = %d\n",n);
}
}
}
if(!find)
printf("There are no solutions for %d.\n",n);
} return ;
}
但要特别提一下这位仁兄写的,有狠多值得学习的地方
http://blog.csdn.net/mobius_strip/article/details/38735773
#include <iostream>
#include <cstdlib>
#include <cstdio> using namespace std; int used[]; int judge( int a, int b )
{
//对于判断是否有重复的数字,可以用一个used数组
//将用过的项置为1 if ( b > ) return ;
for ( int i = ; i < ; ++ i )
used[i] = ;
if ( a < ) used[] = ;
while ( a ) {
used[a%] = ;
a /= ;
}
while ( b ) {
used[b%] = ;
b /= ;
}
int sum = ;
for ( int i = ; i < ; ++ i )
sum += used[i];
return (sum == );
} int main()
{
int n, T = ;
while ( ~scanf("%d",&n) && n ) {
if ( T ++ ) printf("\n");
int count = ;
for ( int i = ; i < ; ++ i ) {
if ( judge( i, i*n ) ) {
printf("%05d / %05d = %d\n",i*n,i,n);
//可以用%05d填充,就不用数组来保存数字了
count ++;
}
}
if ( !count )
printf("There are no solutions for %d.\n",n);
}
return ;
}
uva 725 DIVISION (暴力枚举)的更多相关文章
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- uva 725 Division(除法)暴力法!
uva 725 Division(除法) A - 暴力求解 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- 紫书 例题 10-2 UVa 12169 (暴力枚举)
就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...
- UVA 725 division【暴力枚举】
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...
- UVa 725 Division (枚举)
题意 : 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a-j恰好为数字0-9的一个排列(可以有前导0),2≤n≤79. 分析 : 最暴力的方法莫过于采用数组存 ...
- uva 725 division(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A
- UVA 725 – Division
Description Write a program that finds and displays all pairs of 5-digit numbers that between them ...
随机推荐
- ROS(机器人URDF模型优化)
URDF模型 xacro优化后的URDF模型 1.精简模型代码(创建宏定义,文件包含) 2.提供可编程接口(常量,变量,数学计算,条件语句) 常量定义: name:base_length的值value ...
- 为服务器设置固定IP地址
为服务器设置固定IP地址 1.获取超级管理员权限 命令:$ su - 输入root密码 2.判断哪个网卡有流量,或者确定需要设置哪个网卡的固定ip 命令:# ifconfig PS:可以查询哪些网卡有 ...
- Spring Boot 入门系列
本系列博文版权 简书 面皮大师 所有,转载请标明原文及出处: http://www.jianshu.com/u/062bd8f1299c 项目地址: https://github.com/daleiw ...
- 总结day5 ---- ,字典的学习,增删改查,以及字典的嵌套, 赋值运算
内容大纲: 一:字典的定义 二:字典的增加 >1:按照key增加, 无则增加,有则覆盖 >2:setdefault() ,无则增加,有则不变 三:字典的删除 >1:pop() ...
- java的MethodHandle类详解
一.总述 java7为间接调用方法提供了MethodHandle类,即方法句柄.可以将其看作是反射的另一种方式. 这是使用MethodHandle调用方法的一个例子: public class T ...
- 平衡树 替罪羊树(Scapegoat Tree)
替罪羊树(Scapegoat Tree) 入门模板题 洛谷oj P3369 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入xx数 删除xx数(若有多个相同 ...
- springcloud(八)-Hystrix熔断器
雪崩效应 在微服务架构中通常会有多个服务层调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服务雪崩效应.服务雪崩效应是一种因“服务提供者”的不可用导致“服务消费者” ...
- phpspreadsheet开发手记
坑安装简单示例通过模板来生成文件释放内存单元格根据索引获取英文列设置值合并单元格居中显示宽度设置批量设置单元格格式直接输出下载自动计算列宽函数formula单元格变可点击的超链 PhpSpreadsh ...
- 【开源组件】FastDFS极速入门与安装
FastDFS是一个开源的轻量级的分布式文件系统,为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供 ...
- emacs26.1 ppa
sudo add-apt-repository ppa:kelleyk/emacssudo apt updatesudo apt install emacs26