class Solution {
public:
int projectionArea(vector<vector<int>>& grid) {
int n = grid.size();
int xyArea = 0, yzArea = 0, zxArea = 0;
for (int i = 0; i < n; i++) {
int yzHeight = 0, zxHeight = 0;
for (int j = 0; j < n; j++) {
xyArea += grid[i][j] > 0 ? 1 : 0;
yzHeight = max(yzHeight, grid[j][i]);
zxHeight = max(zxHeight, grid[i][j]);
}
yzArea += yzHeight;
zxArea += zxHeight;
}
return xyArea + yzArea + zxArea;
}
};
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b87175d6599786c8edb0766c68742821.jpeg)
class Solution {
public:
int minimumLines(vector<vector<int>>& stockPrices) {
sort(stockPrices.begin(), stockPrices.end());
int n = stockPrices.size();
if (n <= 2) {
return n - 1;
}
int res = 1;
for (int i = 2; i < n; ++i) {
long long dx0 = stockPrices[i-1][0] - stockPrices[i-2][0];
long long dy0 = stockPrices[i-1][1] - stockPrices[i-2][1];
long long dx1 = stockPrices[i][0] - stockPrices[i-1][0];
long long dy1 = stockPrices[i][1] - stockPrices[i-1][1];
if (dx0 * dy1 != dy0 * dx1) {
++res;
}
}
return res;
}
};
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cff98858bcf3e97cec42ebdaeee46f2e.jpeg)
class Solution {
public:
int GetLenSquare(vector<int> point1, vector<int> point2) {
return (point2[0] - point1[0]) * (point2[0] - point1[0]) + (point2[1] - point1[1]) * (point2[1] - point1[1]);
}
bool validSquare(vector<int>& p1, vector<int>& p2, vector<int>& p3, vector<int>& p4) {
unordered_set<int> set =
{
GetLenSquare(p1, p2),
GetLenSquare(p1, p3),
GetLenSquare(p1, p4),
GetLenSquare(p2, p3),
GetLenSquare(p2, p4),
GetLenSquare(p3, p4)
};
if (set.find(0) == set.end() && set.size() == 2)
{
return true;
}
return false;
}
};
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3a96dad12ef7c2be8862bb4695286f16.jpeg)