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 ...
随机推荐
- VMware 虚拟机报错解决
Could not apply the stored configuration for monitors none of the selected modes were compatible wit ...
- POJ 2209
#include<iostream> #include<stdio.h> #include<algorithm> #include<math.h> #d ...
- python3.6的request
request实例1: import requests payload = {'key1':'value','key2':'value2'} url = "http://httpbin.or ...
- 2. 需要对测试用的数据进行MD5加密
import hashlib phone_num = open("D:/testdata/phone10.txt","r") out_file = open(& ...
- springboot(十三)-分库分表-手动配置
sharding-jdbc简介 Sharding-JDBC直接封装JDBC API,可以理解为增强版的JDBC驱动,旧代码迁移成本几乎为零: 可适用于任何基于java的ORM框架,如:JPA, Hib ...
- JavaScript《一》
脚本语言概念:不需要提前编译的,即时执行的语言,如js,t-sql等 在一个js块中,只要有一个语句出现错误,整个块都不执行 强类型:在编译时就已经确定的类型,弱类型,在运行时,编译器自动根据赋值在确 ...
- 南昌 Max answer
https://nanti.jisuanke.com/t/38228 Alice has a magic array. She suggests that the value of a interva ...
- mysql grant权限总结
2019-01-07 转自 https://blog.csdn.net/wulantian/article/details/38230635 一.权限表 mysql数据库中的3个权限表:user .d ...
- 一张图说清楚SQL的Join
话不多说..看图
- 布局优化之ViewStub、Include、merge使用分析
布局技巧 在Android开发过程中,我们会遇到很多的问题,随着UI界面越来越多,布局的重复性.复杂度也随之增加,所幸的是,Android官方也给出了几个对布局进行优化的方法,下面根据自己的理解对官方 ...