本文整理汇总了C++中Poly::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ Poly::empty方法的具体用法?C++ Poly::empty怎么用?C++ Poly::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poly
的用法示例。
在下文中一共展示了Poly::empty方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: conv
// Slow convolution, multiplying two polynomials.
// Complexity: O(nu * nv).
void conv(const Poly& u, const Poly& v, Poly& w) {
if(u.empty() || v.empty()) {w.clear(); return;}
int nu = u.size(), nv = v.size();
w.assign(nu + nv - 1, 0);
for(int i = 0; i < nu; i++)
for(int j = 0; j < nv; j++)
w[i+j] ^= (u[i] & v[j]);
tidy(w);
}
示例2: divide
Poly divide(Poly const &a, Poly const &b, Poly &r) {
Poly c;
r = a; // remainder
assert(!b.empty());
const unsigned k = a.degree();
const unsigned l = b.degree();
c.resize(k, 0.);
for(unsigned i = k; i >= l; i--) {
assert(i >= 0);
double ci = r.back()/b.back();
c[i-l] += ci;
Poly bb = ci*b;
//std::cout << ci <<"*(" << b.shifted(i-l) << ") = "
// << bb.shifted(i-l) << " r= " << r << std::endl;
r -= bb.shifted(i-l);
r.pop_back();
}
//std::cout << "r= " << r << std::endl;
r.normalize();
c.normalize();
return c;
}
示例3: reduce
void reduce(Poly &v)
{
while (!v.empty() && v.back() % MOD == 0)
{
v.pop_back();
}
}
示例4: gcd
// GCD
void gcd(const Poly& m, const Poly& n, Poly& w) {
if(n.empty()) {
w = m;
return;
}
Poly q, r;
deconv(m, n, q, r);
gcd(n, r, w);
}
示例5: gcd
Poly gcd(Poly const &a, Poly const &b, const double tol) {
if(a.size() < b.size())
return gcd(b, a);
if(b.empty())
return a;
if(b.size() == 1)
return a;
Poly r;
divide(a, b, r);
return gcd(b, r);
}
示例6: checkCollision
float checkCollision(const Poly& a, const Poly& b, Vec2* pnormal, Vec2* pwhere) {
Vec2 normal;
Vec2 where;
if (a.empty() || b.empty()) return 0;
float distance = 9e99;
for (size_t m = 0; m < 2; m++) {
const Poly* pa = m ? &a : &b;
const Poly* pb = m ? &b : &a;
Vec2 p1 = pa->back();
for (Vec2 p2: *pa) {
float c_d = 0;
Vec2 c_n;
Vec2 c_w;
Vec2 n = {p1.y - p2.y, p2.x - p1.x};
for (Vec2 w: *pb) {
float d = (p1.x - w.x) * n.x + (p1.y - w.y) * n.y;
if (d > c_d) {
c_d = d;
c_n = n;
c_w = w;
}
}
if (c_d == 0) return 0;
float ool = 1 / sqrtf(n.x * n.x + n.y * n.y);
c_d *= ool;
if (c_d < distance) {
distance = c_d;
if (m == 1) ool = -ool;
normal = n * ool;
where = c_w;
}
p1 = p2;
}
}
if (pnormal) *pnormal = normal;
if (pwhere) *pwhere = where;
return distance;
}
示例7: is_zero
bool is_zero(Poly p)
{
reduce(p);
return p.empty();
}
示例8: tidy
// Simplify the polynomial, eliminates the high-degree zero term.
void tidy(Poly& c) {
while(!c.empty() && c.back() == 0)
c.pop_back();
}