313. Super Ugly Number - 思路详解

题目

Write a program to find the nth super ugly number.

Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super ugly numbers given primes = [2, 7, 13, 19] of size 4.

Note:
(1) 1 is a super ugly number for any given primes.
(2) The given numbers in primes are in ascending order.
(3) 0 < k ≤ 100, 0 < n ≤ 106, 0 < primes[i] < 1000.

题目翻译

超级素数,素因子只包含规定素因子序列的元素。然后求第n个超级素数。

注意:
1,1是超级素数
2,给的素因子序列为升序

分析

该题可以任务是丑数的一个变种。只是素因子变为了一个素数序列。本质没有变。所以思路请出门右转,看
264. Ugly Number II-思路详解 http://blog.youkuaiyun.com/SJWL2012/article/details/53192810

代码

class Solution {
public:
    int nthSuperUglyNumber(int n, vector<int>& primes) {
        int primes_size = primes.size();
        int *pUglyNumber  = new int[n];

        pUglyNumber[0] = 1;
        int nextUglyIndex = 1;

        vector<int*> pMultiN(primes_size,pUglyNumber);    //初始化

        while(nextUglyIndex < n){
            int min = FindMin(pMultiN,primes);

            pUglyNumber[nextUglyIndex] = min;

            for(int i = 0; i < primes_size; i ++){
                while(*(pMultiN[i])*primes[i] <= pUglyNumber[nextUglyIndex]){
                    ++pMultiN[i];
                }
            }

            ++nextUglyIndex;
        }

        int ugly = pUglyNumber[n-1];
        delete[] pUglyNumber;

        return ugly;
    }


    int FindMin(vector<int*> &pMultiN,vector<int> &primes){
        int primes_size = primes.size();
        int min = *(pMultiN[0])*primes[0];

        for(int i = 1; i < primes_size; ++i){
            if(*(pMultiN[i])* primes[i] < min){
                min = *(pMultiN[i])* primes[i];
            }
        }
        return min;
    }

};
以下是什么错该怎么解决Warning: Group gnome-desktop does not have any packages to install. Warning: Group guest-agents does not have any packages to install. Package gtk2-immodule-xim-2.24.31-1.el7.x86_64 already installed and latest version Package imsettings-gsettings-1.6.3-11.el7.x86_64 already installed and latest version Package ibus-gtk3-1.5.17-14.el7_9.x86_64 already installed and latest version Package ibus-gtk2-1.5.17-14.el7_9.x86_64 already installed and latest version Package gtk3-immodule-xim-3.22.30-8.e17_9.x86_64 already installed and latest version Warning: Group input-methods does not have any packages to install. Group imput-methods does have 2 conditional packages, which may get installed. Warning: Group java-platform does not have any packages to install. Warning: Group guest-desktop-agents does not have any packages to install. Warning: Group fonts does not have any packages to install. Warning: Group print-client does not have any packages to install. Warning: Group desktop-debugging does not have any packages to install. Warning: Group dial-up does not have any packages to install. Warning: Group directory-client does not have any packages to install. Package gstreamer1-plugins-bad-free-1.10.4-4.e17_9.x86_64 already installed and latest version Package gstreamer1-plugins-good-1.10.4-2.el7.x86_64 already installed and latest version Package gstreamer1-plugins-ugly-free-1.10.4-3.e17.x86_64 already installed and latest version Warning: Group multimedia does not have any packages toinstall. Warning: Group base does not have any packages to install. Group base does have 1 conditional packages, which may get installed. Warning: Group internet-browser does not have any packages to install. Warning: Group x11 does not have any packages to install. Warning: Group networkmanager-submodules does not have any packages to install. Warning: Group network-file-system-client does not have any packages to install. Warning: Group graphical-admin-tools does not have any packages to install. Group graphical-admin-tools does have 1 conditional packages, which may get installed. Maybe run: yum groups mark install (see man yum) No packages in any requested group available to install or update
09-10
虽然参考引用中未直接提及解决安装软件包时多个组无可用安装包及无请求组软件包可安装更新问题的内容,但可以从常见的软件包安装原理角度给出一些可能的解决办法。 ### 检查软件源配置 软件源配置不正确可能导致无法获取到可用的软件包。可以检查软件源的设置,确保其指向了正确且可用的镜像地址。以Conda为例,可修改配置文件`.condarc`,示例如下: ```plaintext channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ - https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r ``` 上述内容展示了Conda可以使用的部分镜像源地址,你可以根据实际情况选择合适的镜像源。 ### 清除缓存 缓存可能会存储一些过时或错误的软件包信息,清除缓存后重新尝试安装。对于Conda,可以使用以下命令清除缓存: ```bash conda clean --all ``` ### 检查网络连接 网络问题可能导致无法从软件源获取软件包信息。确保网络连接正常,可尝试访问软件源的网址,检查是否能够正常访问。 ### 检查依赖关系 有些软件包的安装依赖于其他软件包,如果依赖不满足,可能会导致无法安装。以RPM包为例,安装时需要考虑包与包之间的依赖性,若不考虑包的依赖性,可以使用`nodeps`命令(不检测依赖性)进行强制卸载;若是该软件包存在多个版本,可以使用`allmatches`命令进行批量卸载 [^1]。 ### 尝试使用其他版本 有时请求的软件包版本可能在当前软件源中不存在,可以尝试指定其他版本进行安装。例如在Conda中,若要防止现有软件包更新,使用`--freeze-installed`选项可能会强制conda安装所请求的软件包的旧版本 [^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值