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(简单计算器)
参考:https://www.cnblogs.com/alex3714/articles/5169958.html import re ret = re.search('\([^()]+\)','(1 ...
- 算法导论-MIT笔记
第一部分 Analysis of Algorithms 算法分析是关于计算机程序性能(performance)和资源利用的理论研究 1 What's more important than perfo ...
- 【JavaScript】动态原型模式创建对象 ||为何不能用字面量创建原型对象?
var proto = ""; function Person(name, age, job) { this.name = name; this.age = age; this.j ...
- Windows下的VMware导入到Mac的VMware Function
在windows下是以文件夹的形式存在的,但是在Mac下是以.vmwarevm为后缀的文件. 操作步骤: 把windows下的虚拟机整个文件夹拷贝到Mac,然后文件夹后面加上.vmwarevm. 然后 ...
- java翻译到mono C#实现系列(3) 获取手机设备信息(残缺,)
using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; ...
- springMVC与Struts2区别
1.拦截级别 Struts2是类级别的拦截,一个类对应一个request上下文 SpringMVC是方法级别的拦截,一个方法对应一个request上下文,而方法同时又跟一个url对应 所以说从架构本身 ...
- 深度学习(六)keras常用函数学习
原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/9769301.html Keras是什么? Keras:基于Theano和TensorFlow的 ...
- python-Lock锁线程同步和互斥
#!/usr/bin/python #coding=utf-8 #线程间通信的同步与互斥操作-锁 import threading a=b=0 lock=threading.Lock() def va ...
- WPF 使用附加属性增加控件属性
使用附加属性增加控件属性,使得这个附加属性在使用的时候没有局限性,可以在任何的控件中使用它来增加所需要的属性,使得控件的属性使用起来非常灵活 一.自定义附加属性 using System; using ...
- Struts2 Validate
1.自定义action继承ActionSupport 2.复写validate方法,因为ActionSupport实现了Validate这个借口,而这个借口中定义了validate方法 3.当请求时, ...