• 除法(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 $2le N le 79$. 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
    ",b , a , n);
    			if(!hasans){
    				hasans = true;
    			}
    		}
    	}
    	if(!hasans){
    		printf("There are no solutions for %d",n);
    	}
    	return 0;
    }
    





  • 相关阅读:
    网络世界中的图片以及相关的处理
    Ninject 2.x细说1.基本使用
    Orchard1.4新功能自动路由(AutoRouter)并附Orchard最新1.4版汉化包
    json的一点总结
    ASP.NET MVC路由扩展:路由映射
    厚积薄发,丰富的公用类库积累,助你高效进行系统开发(12) 网络相关操作辅助类
    IIS是如何处理ASP.NET请求的
    一周最新示例代码回顾 (3/19–3/25)
    .NET插件系统(三) 插件间通信问题——设计可自组织和注入的组装程序
    缓存总结
  • 原文地址:https://www.cnblogs.com/lvyahui/p/4009959.html
Copyright © 2020-2023  润新知