除法(Division ,UVA 725)-ACM集训
参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html
算法学到很弱,连这么简单个问题都难到我了。但我偏不信这个邪,终于做出来了。不过,是参照别人的,是 xiaobaibuhei 到博客让我找到到感觉,不过我只看了一遍他到代码,后面都是自己写的,虽然写的很像。。。
Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where
. That is,
abcde / fghij = N
where each letter represents a different digit. The first digit of one of the numerals is allowed to be zero.
Input
Each line of the input file consists of a valid integer N. An input
of zero is to terminate the program.
Output
Your program have to display ALL qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator).
Your output should be in the following general form:
xxxxx / xxxxx = N
xxxxx / xxxxx = N
.
.
In case there are no pairs of numerals satisfying the condition, you must write ``There are no solutions for N.". Separate the output for two different values of N by a blank line.
Sample Input
61
62
0
Sample Output
There are no solutions for 61. 79546 / 01283 = 62
94736 / 01528 = 62
//============================================================================
// Name : uva 725
// Author : lvyahui
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
#include <cstdio>
#include <list>
#include <cstring>
using namespace std; char str[10];
bool val[10]; bool check(int a,int b){
bool isok = true;
sprintf(str,"%05d%05d",a,b);
memset(val,false,sizeof(val));
for (int i = 0; i < 10; ++i) {
if(val[str[i]-'0']){
isok = false;break;
}
val[str[i]-'0'] = true;
}
return isok;
}
int main() {
int n; memset(val,0,sizeof(val));
scanf("%d",&n);
int b;
bool hasans = false;
for(int a=1234;a < 49383;a++){// b最大到98765 除2就是49383
// b / a = n
b = a * n;
if(b >= 98765){
break;
}
if(check(a,b)){
printf("%05d / %05d = %d\n",b , a , n);
if(!hasans){
hasans = true;
}
}
}
if(!hasans){
printf("There are no solutions for %d",n);
}
return 0;
}
除法(Division ,UVA 725)-ACM集训的更多相关文章
- 暴力求解——除法 Division,UVa 725
Description Write a program that finds and displays all pairs of 5-digit numbers that between them u ...
- uva 725 Division(除法)暴力法!
uva 725 Division(除法) A - 暴力求解 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- UVA 725 UVA 10976 简单枚举
UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...
- yzm10的ACM集训小感
7月30号,ACM集训进行了两周,一切都已on the right way.这时的我适时地从题海中探出头,其实除了刷题,也该写点什么来总结下过去.首先,在第一周里,我学习了数据结构,知道了STL这么一 ...
- Uva 725 Division
0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...
- uva 725 division(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A
随机推荐
- IronPython fail to add reference to WebDriver.dll
在使用Ironpython引用WebDriver程序集做web自动化时碰到这个问题,出问题的代码很简单,如下: import sys import clr clr.AddReferenceToFile ...
- .\Obj\uCOSDemo.axf: Error: L6218E: Undefined symbol LCD_Fast_DrawPoint (refe
这个问题是 没有定义此函数 解决方法是 定义并声明一下 这个函数!!!
- 层层递进Struts1(八)之总结
先来看一下Struts1学习总结的思维导图,画的主要是Struts1中的重点和博客分布,如下所示: 系列博客的侧重点是: Struts1是什么? 为什么要使用它? 如何使用Struts1? Strut ...
- php session already send by ……
初学者在处理登录注册的时候可能会遇到一个问题就是Warning: Cannot modify header information - headers already sent by .... 这是什 ...
- AE二次开发中,过滤后的图层,实现缩放至图层效果
//featureClass是自己获取的featureClass,也可是sde中获取的. public void FilterAndZoomToLayer(IFeatureClass featureC ...
- Javascript --扩展String实现替换字符串中index处字符
String.prototype.replaceCharAt = function(n,c){ return this.substr(0, n)+ c + this.substr(n+1,this.l ...
- linux下的僵尸进程处理SIGCHLD信号
什么是僵尸进程? 首先内核会释放终止进程(调用了exit系统调用)所使用的所有存储区,关闭所有打开的文件等,但内核为每一个终止子进程保存了一定量的信息.这些信息至少包括进程ID,进程的终止状态,以及该 ...
- 关于URL 解码, 编码
由于近期客户需要用到CA认证,此CA认证采用的是URL方式出传值 使用指定的编码对象将 URL 编码的字符串转换为已解码的字符串. 编码个人理解就是将某字符串以某种方式储存起来,而解码则以其编码格式得 ...
- HTML5-36d嗨起^_^
如果一个前端不会写css那必然会被贻笑大方,利用html5新增的一些c3属性可以做许许多多炫酷的效果. 大家先看我写的一个小demo: http://zpf92.github.io/build/ 这个 ...
- Eclipse 打开时“发现了以元素'd:skin'”开头的无效内容。此处不应含有子元素(转)
打开 Eclipse 时,如图所示: 解决办法: 把有问题的 devices.xml 文件删除,再把 sdk 里面 tools\lib 下的这个文件拷贝到你删除的那个文件夹里,重启 eclipse 就 ...