除法(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
随机推荐
- JDBC高级部分
/** 采用模版类型,封装了基本数据的CRUD操作 基本属性从外部属性文件读取(如config.properties) */public class BaseDao<T> { privat ...
- Anjuta 调试无输出 warning: GDB: Failed to set controlling terminal
调试无输出,起初以为是那个warning的问题,后来才知道这个系统printf直到遇到'\n'换行符才输出,VC6用习惯了没想到还有这样的,网上说这样是节省系统资源. 那个warning暂时还没看到影 ...
- weekend110(Hadoop)的 第六天笔记
(2015年1月25日) 课程目录 01-复习ha相关 02-hive的元数据库mysql方式安装配置 03-hive的使用 04-hive的常用语法 05-hql语法及自定义函数 06-hbase表 ...
- Conversion between json and object
public static string ObjToJson<T>(T obj) { DataContractJsonSerializer serializer = new DataCon ...
- Cadence 信号完整性(一)-- 仿真步骤3
(2)单击“Identify DC Nets”,弹出“Identify DC Nets”窗口,如图2-6 所示: 图 2-6 Identify DC Nets 窗口 (3)在“Net”列表中选择网络如 ...
- gitlab 启动参考
第一步 启动gitlab bundle exec rails s -e production -d 第二步 启动redis /etc/init.d/redis start chkconfig redi ...
- Android编程动态创建视图View的方法
在Android开 发中,在Activity中关联视图View是一般使用setContentView方法,该方法一种参数是使用XML资源直接创 建:setContentView (int layout ...
- android 46 service
service是安卓四大组建之一,service只能系统创建不能new,service也要在项目清单中注册说明,service分为2中,一种是系统级的服务,一种是我们自己写的服务. 启动和关闭serv ...
- Qt c++11
借助 Qt 5 的信号槽语法,我们可以将一个对象的信号连接到 Lambda 表达式,例如: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // !!! Q ...
- Maven学习总结——聚合与继承
一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 1 <modules> 2 <module>模块一</module&g ...