• 带分数 全排列


    问题描述
    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

    9个数字全部出现且只出现1次不就是全排列了,复杂度O(9!)也不是太大,+和/再分割为三部分 判断就可以了

    #include<iostream>
    #include<cstring>
    #include<vector>
    #include<set>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const int N=1000010;
    vector<int> ve;
    int n,a[15],ans=0;
    
    int get(int l,int r)
    {
    	int res=0;
    	for(int i=l;i<=r;i++)
    		res=res*10+a[i];
    	return res;
    }
    int main()
    {
    	cin>>n;
    	for(int i=0;i<9;i++) a[i]=i+1;
    	do
    	{
    		for(int i=0;i<9;i++)
    		{
    			int b=get(0,i),c,d;
    			if(b>=n) break;
    			for(int j=i+1;j<8;j++)
    			{
    				c=get(i+1,j);
    				d=get(j+1,8);
    				//cout<<b<<' '<<c<<' '<<d<<endl;
    				if(c%d==0&&n==b+c/d) ans++;
    			}
    		}
    	}while(next_permutation(a,a+9));
    	cout<<ans;
    	return 0;
    }
    
  • 相关阅读:
    爬虫之Selenium库
    爬虫之pyquery库
    爬虫之BeautifulSoup库
    爬虫之Requests库
    爬虫之Re库
    在Flask中使用Celery
    Celery-分布式任务队列
    MongoDB
    Redis Cluster
    如何使用mongo shell
  • 原文地址:https://www.cnblogs.com/neflibata/p/12871777.html
Copyright © 2020-2023  润新知