当前位置: 首页>>代码示例>>C++>>正文


C++ Sum函数代码示例

本文整理汇总了C++中Sum函数的典型用法代码示例。如果您正苦于以下问题:C++ Sum函数的具体用法?C++ Sum怎么用?C++ Sum使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Sum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Sum

void OpenSMOKE_SensitivityAnalysis::GiveMe_SensitivityCoefficients(const double deltat)
{
	// Implicit Method
	if (iImplicit == true)
	{
		JAlfa *= deltat;
		Sum(JAlfa, Sold, &Sold);
		Jacobian *= -deltat;
		Sum(I,Jacobian, &Jacobian);

		BzzFactorizedGauss AFactorized(Jacobian);
		Solve(&AFactorized, Sold, &S);
	}
/*	else
	// Explicit Method
	{
		Product(JacobianOld, Sold, &S);
		Sum(JacobianOld, JalfaOld, &JacobianOld);

		JacobianOld	*= deltat;
				
		Sum(Sold, JacobianOld, &S);
	}*/

	// Update old value
	Sold = S;
}
开发者ID:acuoci,项目名称:OpenSMOKE,代码行数:27,代码来源:OpenSMOKE_SensitivityAnalysis.cpp

示例2: main

int main()
{
    int N = 50;
    
    int PenDrive = 4000;
    int *Arquivos = (int*)malloc(sizeof(int) * N);
    GenerateFiles(Arquivos, N, 300);

    int *Arq = Sort(Arquivos,N);


    printf("Total espeaço: %i\n", PenDrive);
    printa(Arq, N);

    int soma = 0, i=0;
    soma = Sum(Arq,N);
    printf("Total Arquivos (MB): %i \n",soma);

    for(i=0;i<N ;i++)
        if(PenDrive >= Arq[i]){
            printf("+ %i MB\n", Arq[i]);
            PenDrive -= Arq[i];
            Arq[i] = 0;
        }

    printf("Sobrou (MB): %i \n",PenDrive);

    soma= Sum(Arq,N);
    printf("Sobrou %i MB nos Arquivos!\n",soma);
    return 0;
}
开发者ID:lucasteles,项目名称:Fundations,代码行数:31,代码来源:pendrive.c

示例3: Sum

vector<vector<int> > FourSum::fourSum(vector<int> &num, int target) {
	vector<Sum> doubleSum;
	vector<vector<int> > result;
	
	for (int i = 0; i < num.size(); i++) {
		for (int j = i + 1; j < num.size(); j++) {
			Sum sum = Sum(num[i]+num[j], i, j);
			doubleSum.push_back(sum);
		}
	}
	sort(doubleSum.begin(), doubleSum.end());
	for (vector<Sum>::iterator i = doubleSum.begin(); i != doubleSum.end(); i++) {
		vector<Sum>::iterator start = lower_bound(doubleSum.begin(), doubleSum.end(), Sum(target-(i->value)));
		if (start != doubleSum.end() && (start->value) + (i->value) == target) {
			vector<Sum>::iterator iter = start;
			while (iter != doubleSum.end() && (iter->value) == (start->value)) {
				if ((iter->x != i->x) && (iter->x != i->y) && (iter->y != i->x) && (iter->y != i->y)) {
					vector<int> elem;
					elem.push_back(num[iter->x]);
					elem.push_back(num[iter->y]);
					elem.push_back(num[i->x]);
					elem.push_back(num[i->y]);
					sort(elem.begin(), elem.end());
					if (find(result.begin(), result.end(), elem) == result.end())
						result.push_back(elem);
				}
				iter++;
			}
		}
	}
	return result;
}
开发者ID:tianyangche,项目名称:leetcode-1,代码行数:32,代码来源:FourSum.cpp

示例4: Product

void OpenSMOKE_KPP_SingleReactor::SolveCSTR_Corrector_Linearized(const double deltat, BzzMatrix &tmpMatrix)
{
	// Reactions	
	kinetics->UpdateProperties(omega_, temperature_, pressure_, R_);
	Product(volume_, R_, &RV_);
	GetJacobian(omega_, tmpMatrix);				// A = d(RV)/domega * Volume/mtot;

	// The formulation is the same, both for deferred=on and deferred=off
	// The difference is the Jacobian calculation (see GetJacobian function)
	if (data_->PredictorCorrector_DeferredConvection() == false || 
		data_->PredictorCorrector_DeferredConvection() == true)
	{
		// Rigth hand side
		Product(-M_, omega_, &rhs_);		//	outflow
		Sum(&rhs_, RV_);				//	reaction
		Sum(&rhs_, mInTot_);			//  inflow
		rhs_ *= deltat/mass_;		
	
		// Matrix
		tmpMatrix *= -deltat;			
		for(int i=1;i<=numberOfSpecies;i++)
			tmpMatrix[i][i] += 1.;
	
		// Linear System solution
		BzzFactorizedGauss AGauss(tmpMatrix);
		Solve(AGauss, &rhs_);

		// Updating
		omega_ += rhs_;
	}
}
开发者ID:gywukun09,项目名称:OpenSMOKE,代码行数:31,代码来源:OpenSMOKE_KPP_SingleReactor.cpp

示例5: main

int main()
{
	freopen("t.in", "r", stdin);
	scanf("%d\n", &n);
	for(int i = 1, a, b; i < n; i ++)
	{
		scanf("%d %d\n", &a, &b);
		Add_Edge(a, b);
		Add_Edge(b, a);
	}
	dfs(1);
	for(int i = 1; i <= n; i ++)
		Update(start[i], exist[start[i]] ^= 1);
	scanf("%d\n", &m);
	while(m --)
	{
		char ctrl;
		int x;
		scanf("%c %d\n", &ctrl, &x);
		if(ctrl == 'C')
		{
			int v;
			exist[start[x]] ^= 1;
			if(exist[start[x]]) v = 1;
			else v = -1;
			Update(start[x], v);
		}
		else
			printf("%d\n", Sum(over[x]) - Sum(start[x] - 1));
	}
}
开发者ID:alxsoares,项目名称:OI,代码行数:31,代码来源:p3321.cpp

示例6: CompressBlock

static void CompressBlock(JPEGCompressor *self,int comp,
const JPEGBlock *current,const JPEGBlock *north,const JPEGBlock *west,
const JPEGQuantizationTable *quantization)
{
	// Calculate EOB context.
	int average;
	if(!north&&!west) average=0;
	else if(!north) average=Sum(0,west);
	else if(!west) average=Sum(0,north);
	else average=(Sum(0,north)+Sum(0,west)+1)/2;

	int eobcontext=Min(Category(average),12);

	// Write EOB bits using binary tree.
	WriteBitString(&self->encoder,current->eob,6,
	self->eobbins[comp][eobcontext],
	self->eobshift);

	// Compress AC components in decreasing order, if any.
	for(unsigned int k=current->eob;k>=1;k--)
	{
		CompressACComponent(self,comp,k,k!=current->eob,current,north,west,quantization);
	}

	// Compress DC component.
	CompressDCComponent(self,comp,current,north,west,quantization);
}
开发者ID:miketwo,项目名称:wilt-compressor,代码行数:27,代码来源:Compressor.c

示例7: main

int main() {
    int n;
    while (scanf("%d", &n) && n < 3) {
        if (n == 0) {
            scanf("%d", &size);
            memset(C, 0, sizeof(C));
        } else if (n == 1) {
            int x, y, a;
            scanf("%d %d %d", &x, &y, &a);
            x += 1;
            y += 1;
            A[x][y] += a;
            Add(x, y, a);
        } else if (n == 2) {
            int l, b, r, t;
            scanf("%d %d %d %d", &l, &b, &r, &t);
            l += 1;
            b += 1;
            r += 1;
            t += 1;
//            printf("%d\n", Sum(max(l, r), max(b, t)) - Sum(min(l, r), max(b, t)));
            printf("%d\n", Sum(r, t) + Sum(l - 1, b - 1) - Sum(r, b - 1) - Sum(l - 1, t));
        }
        for (int i = 0; i <= 10; i++) {
            for (int j = 0; j <= 10; ++j) {
                printf("%d ", C[i][j]);
            }
            printf("\n");
        }
        printf("\n");
    }
}
开发者ID:sorcererXW,项目名称:ACM,代码行数:32,代码来源:1195.cpp

示例8: Sum

 //s is the previous sum from the ancestors
 int Sum(TreeNode* root, int s)
 {
     if(!root) return 0;
     //reaches the leaf, calculate this path sum
     if((!root->left)&&(!root->right)) return s*10+root->val;
     //recurse into the left and right subtree
     return Sum(root->left,s*10+root->val)+Sum(root->right,s*10+root->val);
 }
开发者ID:XiaowenJiang,项目名称:leetcode_cplusplus,代码行数:9,代码来源:SumRoottoLeafNumbers.cpp

示例9: TEST

TEST(Util, SumTest) {
    VVReal tmp;
    Init(2, 2, 1.0, &tmp);
    EXPECT_DOUBLE_EQ(4, Sum(tmp));
    VVVReal tmp2;
    Init(2, 2, 2, 2.0, &tmp2);
    EXPECT_DOUBLE_EQ(16, Sum(tmp2));
}
开发者ID:BigdataMachinelearning,项目名称:project,代码行数:8,代码来源:util_unittest.cpp

示例10: Flacker

func Flacker()
{
  if(Not(Random(15))) And(CastObjects(SU3V,Sum(1,Random(1)),Sum(5,Random(15)),Sum(-14,Random(28)),Sum(1,Random(2))),Sound("Spark*"));
  if(Not(Random(2))) return(0);
  if(Random(6)) return(ObjectSetAction(Local(0),"Neon")&&SetAction("FlackerAn"));
  if(Random(6)) return(ObjectSetAction(Local(0),"Aus")&&SetAction("FlackerAus"));
  return(1);
}
开发者ID:Fulgen301,项目名称:SGGP,代码行数:8,代码来源:Script.c

示例11: StartTimer

void LayerConv::CalcWeights(Layer *prev_layer, int passnum) {
  StartTimer();

  if (passnum < 2) return;
  Mat weights_der;
  if (passnum == 2) {
    weights_der.attach(weights_.der());
  } else if (passnum == 3) {
    weights_der.attach(weights_.der2());    
  }
  #if COMP_REGIME != 2
    std::vector< std::vector<Mat> > prev_activ, filters_der, deriv;
    InitMaps(prev_layer->activ_mat_, prev_layer->mapsize_, prev_activ); 
    InitMaps(weights_der, filtersize_, filters_der);
    InitMaps(deriv_mat_, mapsize_, deriv);
    size_t i,j;
    int k;
    //#pragma omp parallel{ //for num_threads(12) private(fil_der)
    for (i = 0; i < outputmaps_; ++i) {
      for (j = 0; j < prev_layer->outputmaps_; ++j) {

        Mat fil_der(filtersize_);
        fil_der.assign(0);      
        #if COMP_REGIME == 1
        #endif
        for (k = 0; k < batchsize_; ++k) {
          Mat ker_mat(filtersize_);
          Filter(prev_activ[k][j], deriv[k][i], padding_, false, ker_mat);      
          #if COMP_REGIME == 1
            //#pragma omp critical
          #endif
          fil_der += ker_mat; 
                   
        }
        filters_der[i][j] = fil_der;        
      }        
    }    
  #else // GPU    
    WeightActs(prev_layer->activ_mat_, deriv_mat_, weights_der,
               prev_layer->mapsize_, filtersize_[0], 
               padding_[0], sum_width_, !unshared_);        
  #endif
  weights_der /= (ftype) batchsize_;
  weights_der.Validate();
  if (passnum == 2) {
    mexAssert(deriv_mat_.order() == false, "deriv_mat_.order() should be false");
    if (!unshared_) {
      deriv_mat_.reshape(batchsize_ * deriv_mat_.size2() / outputmaps_, outputmaps_);
      Sum(deriv_mat_, biases_.der(), 1);
      deriv_mat_.reshape(batchsize_, deriv_mat_.size1() * outputmaps_ / batchsize_);        
    } else {
      Sum(deriv_mat_, biases_.der(), 1);      
    }
    (biases_.der() /= (ftype) batchsize_) *= bias_coef_;
    biases_.der().Validate();
  }
  MeasureTime("CalcWeights Conv Layer",2);
}
开发者ID:mwoodson1,项目名称:NeuroPhi,代码行数:58,代码来源:layer_c.cpp

示例12: FindTotal

	wxInt32 FindTotal(wxInt32 player)
	{
		wxInt32 total = 0;
		total += Sum(shPlayableTradeCards, player);
		total += Sum(shPlayableScienceCards, player);
		total += Sum(shPlayablePoliticsCards, player);

		return total;
	}
开发者ID:Dangr8,项目名称:Cities3D,代码行数:9,代码来源:RuleRestartDiscardProgressCards.cpp

示例13: Tupdate

inline void Tupdate(int x)
{
    Size(x)=Size(Lch(x))+1+Size(Rch(x));
    Sum(x)=Sum(Lch(x))+Val(x)+Sum(Rch(x));
    Lms(x)=max(Lms(Lch(x)),Sum(Lch(x))+Val(x)+Lms(Rch(x)));
    Rms(x)=max(Rms(Rch(x)),Rms(Lch(x))+Val(x)+Sum(Rch(x)));
    Ms(x)=Rms(Lch(x))+Val(x)+Lms(Rch(x));
    if (Lch(x))    Ms(x)=max(Ms(x),Ms(Lch(x)));
    if (Rch(x))    Ms(x)=max(Ms(x),Ms(Rch(x)));
}
开发者ID:9Gaurav9Jain9,项目名称:cat-us-trophy,代码行数:10,代码来源:orgsplay.cpp

示例14: Code4

void Code4() {
  int i_array[] = {1, 2, 3};
  std::cout << Sum(i_array, 0) << "\n";
  std::vector<int> i_vec = {4, 5, 6};
  std::cout << Sum(i_vec, 0) << "\n";
  std::vector<std::string> str_vec = {
    "ふるいけや", "かわずとびこむ", "みずのおと"
  };
  std::cout << Sum(str_vec, std::string("")) << "\n";
}
开发者ID:tyamag,项目名称:cpp_seminar,代码行数:10,代码来源:main.cpp

示例15: pull

void pull( Treap * a ){
	a->sum = Sum( a->l ) + Sum( a->r ) + a->val;
	a->lsum = Sum( a->l ) + a->val + max( 0 , lSum( a->r ) );
	if( a->l ) a->lsum = max( lSum( a->l ) , a->lsum );
	a->rsum = Sum( a->r ) + a->val + max( 0 , rSum( a->l ) );
	if( a->r ) a->rsum = max( rSum( a->r ) , a->rsum );
	a->maxsum = max( 0 , rSum( a->l ) ) + a->val + max( 0 , lSum( a->r ) );
	a->maxsum = max( a->maxsum , max( maxSum( a->l ) , maxSum( a->r ) ) );
	a->sz = Size( a->l ) + Size( a->r ) + 1;
}
开发者ID:tzupengwang,项目名称:PECaveros,代码行数:10,代码来源:treap_test.cpp


注:本文中的Sum函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。