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 ...
随机推荐
- python 取出字典的键或者值/如何删除一个字典的键值对/如何遍历字典
先定义一个字典并直接进行初始化赋值 my_dict = dict(name="lowman", age=45, money=998, hourse=None) 1.取出该字典所有的 ...
- 打开SQL Server2000企业管理器时候提示“MMC 无法创建管理单元 ”
今天上午在打开SQL Server 2000 企业管理器时候提示“MMC 无法创建管理单元”错误.
- 资产管理 cmdb之ansible 获取服务器硬件、软件等信息
cmdb抓取服务信息的方式有很多种,可以使用自动化工具saltstack.ansible.puppet,或者使用其它模块直接ssh远程连接抓取服务器信息.这里记录一下用ansible的API接口调用s ...
- 核心API的使用(给定一个字符串,统计每个字符出现的次数)
/** * 给定一个字符串,统计每个字符出现的次数. 如:abdaewrwqask435a1aasd */public class ReplaceString { static int length; ...
- Asp.net的生命周期应用之IHttpHandler
摘自:http://www.cnblogs.com/JimmyZhang/archive/2007/09/15/894124.html Framework提供了一系列的接口和类,允许你对于Http请求 ...
- linux常见编辑命令
保存命令 按ESC键 跳到命令模式,然后: :w 保存文件但不退出vi :w file 将修改另外保存到file中,不退出vi :w! 强制保存,不推出vi :wq 保存文件并退出vi :wq! 强制 ...
- java源码解析之Object类
一.Object类概述 Object类是java中类层次的根,是所有类的基类.在编译时会自动导入.Object中的方法如下: 二.方法详解 Object的方法可以分成两类,一类是被关键字fin ...
- ZigZag编码
ZigZag编码 在网络传输和数据存储场景中,需要对数据进行压缩.数据压缩的算法非常多,但大部分的数据压缩算法的原理是通过某种编码方式不存储数据中的0比特位,因此0比特位越多,数据压缩的效果越好.Zi ...
- 手动添加Git Bash到右键菜单
1. 打开注册表. 2. 找到[HKEY_CLASSES_ROOT\Directory\Background]. 3. 在[Background]下如果没有[shell],则右键-新建项[shell] ...
- golang实现kafka的消息推送
Kafka的安装与启动 kafka中涉及的名词 消息记录:由一个key,一个value和一个时间戳构成,消息最终存储在主题下的分区中,记录在生产中称为生产者记录,在消费者中称为消费记录.Kafka集群 ...