lc812.鞋带公式
s=三个梯形
梯形计算:
1/2*(上底+下底)*高=1/2*(y和)*(x差)
成功转化为了point坐标计算~
忽想起7月有场周赛题,求的是梯形面积

class Solution {
public:
double largestTriangleArea(vector<vector<int>>& points) {
const int N = points.size();
double res = 0;
for (int i = 0; i < N - 2; i ++) {
for (int j = i + 1; j < N - 1; j ++) {
for (int k = j + 1; k < N; k ++) {
auto& point1 = pointsi;
auto& point2 = pointsj;
auto& point3 = pointsk;
int x1 = point10, y1 = point11;
int x2 = point20, y2 = point21;
int x3 = point30, y3 = point31;
res = max(res, 0.5 * abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)));
}
}
}
return res;
}
};
lc1208
前缀和+滑窗
class Solution {
public:
int equalSubstring(string s, string t, int maxCost) {
int n = s.size();
vector<int> pre(n + 1, 0);
// pre0 = 0,方便计算区间和
for (int i = 0; i < n; i++) {
prei + 1 = prei + abs(si - ti);
}
int ret = 0;
for (int l = 0, r = 0; r < n; r++) {
// 找到最小的 left 使得 preright + 1 - preleft > maxCost
++while (prer + 1 - prel > maxCost)
{
l++;
}++
ret = max(ret, r - l +++ 1);++
}
return ret;
}
};
lc299
class Solution {
public:
string getHint(string secret, string guess)
{
int n=secret.size();
vector<bool> prec(n,false);
int a=0,b=0;
unordered_map<char,int> hash;
for(int i=0;i<n;i++)
{
if(secreti==guessi)
{
preci=true;
a++;
}
else
{
hashguess\[i]++;
}
}
for(int i=0;i<n;i++)
{
char s=secreti;
if(hash.count(s) && !preci)
{
b++;
hashs--;
if(hashs==0)
hash.erase(s);
}
}
string ret;
string aa=to_string(a);
ret+=aa;
ret+="A";
string bb=to_string(b);
ret+=bb;
ret+="B";
return ret;
}
};
lc01.08
开数组存一下
class Solution {
public:
void setZeroes(vector<vector<int>>& matrix)
{
int m=matrix.size(),n=matrix0.size();
vector<vector<int>> t=matrix;
function<void(int,int)> dfs=\&(int a,int b)
{
for(int i=0;i<m;i++)
tib=0;
for(int j=0;j<n;j++)
taj=0;
};
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(matrixij==0)
{
dfs(i,j);
}
}
}
matrix=t;
}
};