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 ...
随机推荐
- k_means算法C++实现,改为面向对象
画的类图如下:
- web渗透-sqli-labs-master 下载与安装
注意事项,写在前面. php版本一定要设置成 7 以下,7之后的mysql_都改成了mysqli_**了,用7以上版本的话会报错 *********************************** ...
- ckeditor4.5.11+ckfinder_java2.6.2配置
http://blog.csdn.net/skyman1942/article/details/52537100 1.环境说明: 日期:2016-09-14 工具:ckeditor_4.5.11+ck ...
- delphi 10.2 ---treeview 基本用法
unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...
- vscode 本地调试nodejs
1.首先通过node-inspect插件可以debug nodejs ,先起nodejs服务,再启用node-inpector服务 安装调试器 npm install -g node-inspec ...
- leetcode-292-Nim Game(搬石子)
题目描述: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl ...
- Django分页的实现
Django分页的实现 Django ORM 分页介绍 分页是网页浏览中常见到的一种形式,在数据量较大时,一个页面显示不全,采取分割数据由用户选择进行显示的方式. 基本实现 技术点 通过切片得到数据 ...
- 【Alpha】Phylab 发布说明
Phylab Alpha阶段发布说明 一.发布地址 Phylab 二.新功能 1. 控制台 由于往届项目控制台并未发布,因此我们在完善后将这部分放在新功能部分.目前使用控制台需要向开发者申请. 1.1 ...
- GeneXus学习笔记——创建一个知识库 哈哈哈哈!
终于想到写什么东西了(绝对不是因为懒 好吧 信我) 那么进入正题 我们写项目的时候 遇到一些问题啥的 总会听到大佬说:“这有什么难的 说到底不就是简单的增删改查么" 然后我们就会露出 Σ ...
- [转] Scala 的集合类型与数组操作
[From] https://blog.csdn.net/gongxifacai_believe/article/details/81916659 版权声明:本文为博主原创文章,转载请注明出处. ht ...