> For the complete documentation index, see [llms.txt](https://hao-fu-1.gitbook.io/oj/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hao-fu-1.gitbook.io/oj/array_and_numbers/825.-friends-of-appropriate-ages.md).

# 825. Friends Of Appropriate Ages

https\://leetcode.com/problems/friends-of-appropriate-ages

数组元素表示人的年龄，统计所有不满足age\[B] <= 0.5 \* age\[A] + 7和age\[B] > age\[A]的AB pair个数，A和自己不能组队。因为年龄的范围很小，所以直接用暴力思路对每个年龄，遍历其它所有年龄，统计满足条件的人数。由于AA不能算，需要特殊处理。

```cpp
class Solution {
public:
    int numFriendRequests(vector<int>& ages) {
        int res = 0;
        vector<int> freqs(121, 0);
        for (const auto a : ages) ++freqs[a];
        for (int i = 0; i < 121; ++i) {
            if (freqs[i] == 0) continue;
            int r = 0;
            for (int j = 0.5 * i + 7 + 1; j <= i; ++j) {
                r += freqs[j];
                if (j == i && freqs[j] > 0) --r;
            }
            res += freqs[i] * r;
        }
        return res; 
    }
};
```
