zoukankan      html  css  js  c++  java
  • 历届试题 带分数

    历届试题 带分数  

    时间限制:1.0s   内存限制:256.0MB
          
    问题描述

    100 可以表示为带分数的形式:100 = 3 + 69258 / 714。

    还可以表示为:100 = 82 + 3546 / 197。

    注意特征:带分数中,数字1~9分别出现且只出现一次(不包含0)。

    类似这样的带分数,100 有 11 种表示法。

    输入格式

    从标准输入读入一个正整数N (N<1000*1000)

    输出格式

    程序输出该数字用数码1~9不重复不遗漏地组成带分数表示的全部种数。

    注意:不要求输出每个表示,只统计有多少表示法!

    样例输入1
    100
    样例输出1
    11
    样例输入2
    105
    样例输出2
    6
     
    #include<iostream>
    #include<string.h>
    using namespace std;
    bool used[10];
    int a[10], N, total;
    void permutation(int pos){
        if (pos == 9){
            int p = 1, q = 9;//+、/位置
            int x, y, z;//x+y/z==N?
            for (p = 1; p < 9; p++){
                x = 0; 
                for (int i = 1; i <= p; i++)x = x * 10 + a[i];
                if (x >= N)break;
                for (q = 9; q>p; q--){
                    y = 0; z = 0;
                    for (int i = q; i <= 9; i++)z = z * 10 + a[i];
                    for (int i = p + 1; i < q; i++)y = y * 10 + a[i];
                    if (z>y)break;
                    if ((y%z==0)&&((x + y / z) == N)){
                        total++;
                        //cout << "x y z " << x << "," << y << "," << z << endl;
                    }
                }
            }
            return;
        }
        for (int i = 1; i < 10; i++){
            if (!used[i]){
                used[i] = true;
                a[pos + 1] = i;
                permutation(pos + 1);
                used[i] = false;
            }
        }
    }
    int main()
    {
        cin >> N;
        total = 0;
        permutation(0);
        cout << total << endl;
        system("pause");
        return 0;
    }
    世上无难事,只要肯登攀。
  • 相关阅读:
    进程&线程
    PLAN
    Note-Virus
    编译器 CL.EXE / RC.EXE
    windows API
    centos6.5系统中yum命令出错
    VMware Workstation10 下安装 CentOS6.5( 安装图文教程 )
    Linux下网络能ping通地址 但是ping不通域名
    MySQL数据库优化的八种方式(经典必看)
    Java中常见的对象类型简述(DO、BO、DTO、VO、AO、PO)
  • 原文地址:https://www.cnblogs.com/littlehoom/p/3561722.html
Copyright © 2011-2022 走看看