记录一下失败的solve
作者:
Soel
,
2023-07-31 01:13:27
,
所有人可见
,
阅读 115
using i64 = long long;
double k = 0;
class node {
public:
int day, price;
};
bool operator< (node &a, node &b){
return a.day < b.day;
}
bool operator > (node& a, node& b) {
return a.day > b.day;
}
class node1 {
public:
int x, y;
};
bool operator == (node1 a, node1 b) {
return std::abs((b.y - a.y + 0.0) / (b.x - a.x + 0.0)-k)<=1e-18;
}
class Solution {
public:
int minimumLines(std::vector<std::vector<int>>& stockPrices) {
std::cout << std::fixed << std::setprecision(18);
std::vector<node> a;
for (auto& x : stockPrices) a.push_back({ x[0],x[1] });
if(a.size()==1) return 0;
auto op1 = [](auto a,auto b) {
return a < b;
};
std::sort(a.begin(), a.end(),op1);
double x0 = a[0].day, y0 = a[0].price;
i64 cnt = 0;
k = 0x3f3f3f3f;
node1 na = { int(x0),int(y0) }, nb = { int(x0),int(y0) };
for (auto& [x, y] : a) {
if (x==x0 and y==y0) continue;
na.x = x0, na.y = y0, nb.x = x, nb.y = y;
if (na == nb) {
std::cout <<"x="<<x<<' '<< "cnt=" << cnt << ' ' << "k=" << k << '\n';
x0 = x, y0 = y;
continue;
}
k = (y - y0) / (x - x0);
x0 = x, y0 = y;
++cnt;
std::cout <<"x="<<x<<' '<< "cnt=" << cnt << ' ' << "k=" << k << '\n';
}
return cnt;
}
};