zoukankan      html  css  js  c++  java
  • 数组全排列 knuth 分解质因数

    template<typename T>
    void swap(T* a, T* b)
    {
    	T temp = *a;
    	*a = *b;
    	*b = temp;
    }
    //数组的全排列
    void perm(int list[], int k, int m)
    {
        if (k==m)
        {
            copy(list,list+m,ostream_iterator<int>(cout," "));
            cout<<endl;
            return;
        }
        for (int i=k; i<m; i++)
        {
        	if(list[k] == list[i] && k != i)
        		continue;
            swap(&list[k],&list[i]);
    		perm(list,k+1,m);
            swap(&list[k],&list[i]);
        }
    }

    void knuth(int n, int m)

    {

             srand((unsigned int)time(0));

           for (int i=0; i<n; i++)

              {

                     if (rand()%(n-i)<m)

                      {

                                    cout<<i<<endl;

                                    --m;

                       }

              }

    }

    
    

    以下prim函数的功能是分解质因数。请填空

    void prim(int m, int n)

    {

        if (m>n)

        {

            while (            ) n++;

                                           ;

           prim(m,n);

           cout<<n<<endl;

        }

    }

    分别为:m%n  和 m/=n

      

  • 相关阅读:
    0425正则数组
    0424php函数
    0424php基础
    string类例题
    数组分为一维数组,二维数组,多为数组
    string类 截取的长度 是否包含某个数
    循环语句2
    /异常语句try,catch.
    string类
    循环语句
  • 原文地址:https://www.cnblogs.com/yi-meng/p/3956774.html
Copyright © 2011-2022 走看看