zoukankan      html  css  js  c++  java
  • 求解复数组 中模较大的N个数

    //求解复数组 中模较大的N个数
    void fianN_Complex(Complex outVec[], int& len, std::vector<int>& index,int N)   // Complex (&outVec)[512]  数组引用  单纯数组做参数退化为指针
    {
        std::vector<double> modulus;
        for (size_t i = 0; i < len; i++)
        {
            double temp;
            temp=sqrt(outVec[i].im*outVec[i].im + outVec[i].rl*outVec[i].rl);
            modulus.push_back(temp);
        }
    
        if (index.size()<N)
        {
            if (index.size()!=0)
            {
                for (size_t i = 0; i < index.size(); i++)
                {
                    modulus[index[i]] = 0;
                }    
            }
    
            int indextemp = 0;
            for (size_t j = 0; j < modulus.size() - 1; j++)
            {
                if (modulus[j]>modulus[j + 1])
                {
                    double temp = modulus[j];
                    modulus[j] = modulus[j + 1];
                    modulus[j + 1] = temp;
                }
                else
                {
                    indextemp = j + 1;
                }
            }
            index.push_back(indextemp);
        }
    
    }
  • 相关阅读:
    password
    bzoj 1458: 士兵占领
    国家集训队2011 happiness
    cogs 2051. 王者之剑
    uva 10779 Collectors Problem
    [Jxoi2012]奇怪的道路
    天神下凡
    藏宝图
    黑红树
    愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/lovebay/p/9842262.html
Copyright © 2011-2022 走看看