1010. 总持续时间可被 60 整除的歌曲

 

class Solution {
public:
    vector<int> v;
    struct node{
        int cnt = 0;
        vector<int> id;

    }Node[1010];
    int numPairsDivisibleBy60(vector<int>& time) {
        
        for(int i = 60; i <= 1000; i += 60)
            v.push_back(i);
        int length = time.size();
        int len = v.size();
        for(int i = 0; i < length; i++)
        {  
            Node[time[i]].cnt++;
            Node[time[i]].id.push_back(i);
        }
        int ans = 0;
        for(int i = 0; i < length; i++)
        {
            for(int j = 0; j < len; j++)
            {
                if(v[j] == time[i]) continue;
                else if(v[j] < time[i] || Node[v[j] - time[i]].cnt == 0) continue;
                else
                {
                    int m = v[j] - time[i];
                    int len2 = Node[m].id.size();
                    for(int k = 0; k < len2; k++)
                        if(Node[m].id[k] > i) ans++;
                }

            }
        }
        return ans;

    }
};

 

上一篇:计算机的二进制


下一篇:TSP问题解析篇之自适应大邻域搜索(ALNS)算法深度通读(附python代码)