3025. 人员站位的方案数 I
Problem: 3025. 人员站位的方案数 I
文章目录
- 思路
- 解题过程
- 复杂度
- Code
思路
暴力枚举。
解题过程
很通俗易懂。
复杂度
- 时间复杂度: O(n3)O(n^3)O(n3)
- 空间复杂度: O(1)O(1)O(1)
Code
class Solution {
public:int numberOfPairs(vector<vector<int>>& points) {int n = points.size();int ans = 0;for (int i = 0; i < n; i++) {int x1 = points[i][0], y1 = points[i][1]; for (int j = 0; j < n; j++) {if (i == j) continue;int x2 = points[j][0], y2 = points[j][1]; if (x1 <= x2 && y1 >= y2) {bool ok = true;for (int k = 0; k < n; k++) {if (k == i || k == j) continue;int x = points[k][0], y = points[k][1];if (x1 <= x && x <= x2 && y2 <= y && y <= y1) {ok = false;break;}}if (ok) ans++;}}}return ans;}
};