void sumN(TreeNode *root, int val, int &sum) { if (root) { if (!root->left && !root->right) { sum += (10 * val + root->val); return ; } sumN(root->left, 10 * val + root->val, sum); sumN(root->right, 10 * val + root->val, sum); } }
void sumN(TreeNode *A,vector<int> &row,int &sum){ if(!A) return; if(!A->left && !A->right){ row.push_back(A->val); sum+=evaluate(row); sum%=1003; row.pop_back(); return; } row.push_back(A->val); sumN(A->left,row,sum); sumN(A->right,row,sum); row.pop_back(); }
NEMO_PLUGIN_DLL_PUBLIC void cpu_update_neurons( unsigned start, unsigned end, unsigned cycle, float* paramBase, size_t paramStride, float* stateBase, size_t stateHistoryStride, size_t stateVarStride, unsigned fbits, unsigned fstim[], RNG rng[], float /*currentEPSP*/[], float /*currentIPSP*/[], float /*currentExternal*/[], uint64_t recentFiring[], unsigned fired[], void* rcm_ptr) { const nemo::runtime::RCM& rcm = *static_cast<nemo::runtime::RCM*>(rcm_ptr); const float* frequency = paramBase + 0 * paramStride; const float* g_Cmean = paramBase + 1 * paramStride; const float* phase0 = phase(stateBase, stateHistoryStride, cycle);// current float* phase1 = phase(stateBase, stateHistoryStride, cycle+1); // next std::vector<float> weight; std::vector<float> sourcePhase; for(unsigned n=start; n < end; n++) { float h = 0.05; const float f = frequency[n]; float targetPhase = phase0[n]; const unsigned indegree = loadIncoming(rcm, n, cycle, stateBase, stateHistoryStride, weight, sourcePhase); float Cmean = g_Cmean[n] > 0 ? g_Cmean[n] : 1; float k0 = f + (sumN(weight, sourcePhase, indegree, targetPhase )/Cmean); float k1 = f + (sumN(weight, sourcePhase, indegree, targetPhase+k0*0.5f*h)/Cmean); float k2 = f + (sumN(weight, sourcePhase, indegree, targetPhase+k1*0.5f*h)/Cmean); float k3 = f + (sumN(weight, sourcePhase, indegree, targetPhase+k2*h )/Cmean); //! \todo ensure neuron is valid //! \todo use precomputed factor and multiply targetPhase += h*(k0 + 2*k1 + 2*k2 + k3)/6.0f; phase1[n] = fmodf(targetPhase, 2.0f*M_PI) + (targetPhase < 0.0f ? 2.0f*M_PI: 0.0f); } }
void Foam::isoCutFace::calcSubFaceCentreAndArea() { const label nPoints = subFacePoints_.size(); // If the face is a triangle, do a direct calculation for efficiency // and to avoid round-off error-related problems if (nPoints == 3) { subFaceCentre_ = sum(subFacePoints_)/scalar(3); subFaceArea_ = 0.5 *( (subFacePoints_[1] - subFacePoints_[0]) ^(subFacePoints_[2] - subFacePoints_[0]) ); } else if (nPoints > 0) { vector sumN(Zero); scalar sumA(0.0); vector sumAc(Zero); const point fCentre = sum(subFacePoints_)/scalar(nPoints); for (label pi = 0; pi < nPoints; pi++) { const point& nextPoint = subFacePoints_[subFacePoints_.fcIndex(pi)]; vector c = subFacePoints_[pi] + nextPoint + fCentre; vector n = (nextPoint - subFacePoints_[pi])^(fCentre - subFacePoints_[pi]); scalar a = magSqr(n); sumN += n; sumA += a; sumAc += a*c; } // This is to deal with zero-area faces. Mark very small faces // to be detected in e.g., processorPolyPatch. if (sumA < ROOTVSMALL) { subFaceCentre_ = fCentre; subFaceArea_ = vector::zero; } else { subFaceCentre_ = (1.0/3.0)*sumAc/sumA; subFaceArea_ = 0.5*sumN; } } subFaceCentreAndAreaIsCalculated_ = true; }
int main(){ int x, arr[SIZE], i; x = enterX(); for(i=1; i<=SIZE; i++){ arr[i-1] = sumN(x*i); } printArr(arr); return 0; }
int sumNumbers(TreeNode *root) { int sum = 0; sumN(root, 0, sum); return sum; }
int Solution::sumNumbers(TreeNode* A) { int sum=0; vector<int>row; sumN(A,row,sum); return sum; }