int main(int argc, char **argv) { int i,a,b,c; FILE * output=stdout; int verbose=0; for(i=1; i < argc; i++) { if(strcmp(argv[i],"-o")==0) output=fopen(argv[++i],"w"); else if(strcmp(argv[i],"-v")==0) verbose=1; else { printf("invalid parameter - %s\n",argv[i]); return 1; } } getNumbers(&a, &b); c = _sum(a,b); if(verbose) fprintf(output, "Welcome to task0, the input numbers are %i and %i\nThe sum is %i\n",a,b,c); fprintf(output,"sum of %i and %i is: %i\n",a,b,c); if(output!=stdout) fclose(output); return 0; }
// Process void Tree::Process() { switch (_step) { case 0: if (_initialize()) _step++; else return; case 1: if (_count()) _step++; else throw std::runtime_error("read error"); case 2: if (_sum()) _step++; else return; case 3: if (_build()) _step++; else throw std::runtime_error("build error"); case 4: if (_subtrees()) _step++; else throw std::runtime_error("subtree error"); default: _fptree.free(); FinishProcess(); } }
void FluidSDF::reconstructSurface(Particles::Ptr particles, float R, float r) { LOG_OUTPUT("Reconstructing fluid surface."); assert(R && r); _sum.reset(); _pAvg.reset(); int nx = _phi.nx(); int ny = _phi.ny(); for (int p = 0; p < particles->numParticles(); ++p) { const int ci = particles->pos(p).x / _phi.dx(); const int cj = particles->pos(p).y / _phi.dx(); assert(ci < _phi.nx() && cj < _phi.ny()); for (int i = std::max(0,ci-2); i < std::min(nx,ci+2); ++i) { for (int j = std::max(0,cj-2); j < std::min(ny,cj+2); ++j) { const Vec2f xd = particles->pos(p) - _phi.pos(i,j); const float k = _kernel(xd.length() / R); _sum(i,j) += k; _pAvg(i,j) += k * particles->pos(p); } } } for (int i = 0; i < _phi.nx(); ++i) { for (int j = 0; j < _phi.ny(); ++j) { if (_sum(i,j) > 0) { _pAvg(i,j) *= (1.0f / _sum(i,j)); const Vec2f xd = _phi.pos(i,j) - _pAvg(i,j); _phi(i,j) = xd.length() - r; } else { _phi(i,j) = _phi.dx() * 1e15; } } } }
LL sum(int l , int r) { LL res = 0; -- l; res += (r + 1) * _sum(B , r) - _sum(C , r); res -= (l + 1) * _sum(B , l) - _sum(C , l); return res; }