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


C++ perm函数代码示例

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


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

示例1: main

void main (void)
{
  int x;
  FILE *F;
  
  if((F=fopen("Nex.log", "w`")) == NULL)
    return;
  fclose(F);
  if((F=fopen("Nex.log", "a")) == NULL)
    return;
  for(x=0; x<N; x++)
    P[x] = x + 1;
  
  perm(0, F);
}
开发者ID:Tegerium,项目名称:SUM2015,代码行数:15,代码来源:T03PERM.C

示例2: perm

void perm(char *list, int i, int n) {
	int j, temp;
	if (i == n) {
		for (j = 0; j <= n; j++)
			printf ("%c", list[j]);
		printf("   ");
	}
	else {
		for (j = i; j <= n; j++) {
			SWAP(list[i], list[j], temp);
			perm(list, i+1, n);
			SWAP(list[i], list[j], temp);
		}
	}
}
开发者ID:4179e1,项目名称:misc,代码行数:15,代码来源:1.8.c

示例3: perm

perm(int k)
{
    int i;
    if(k==n)
    print();
    else
    {
        for(i=k;i<=n;i++)
        {
            swap(&a[i],&a[k]);
            perm(k+1);
            swap(&a[i],&a[k]);
        }
    }
}
开发者ID:sagar55,项目名称:MyProg,代码行数:15,代码来源:perm.c

示例4: perm

void perm(int Pos, FILE *F)
{
  int i, x, save;
  if(Pos == N)
  {
    for(i=0; i<N; i++)
      fprintf(F ,"%d ", P[i]);
    fprintf(F, " - %s\n", Parity ? "odd" : "even");
    return;
  }   
  save = Parity;
  perm(Pos +1, F);
  for(i = Pos +1; i< N; i++)
  {
    Parity = !Parity;
    swap(&P[Pos], &P[i]);
    perm(Pos +1, F);
  }
  Parity = save;
  x = P[Pos];
  for(i = Pos +1; i< N; i++)
    P[i - 1] = P[i] ;
  P[N-1] = x;
}
开发者ID:Tegerium,项目名称:SUM2015,代码行数:24,代码来源:T03PERM.C

示例5: main

main()
{
	int n=2;
	char s[N];
	w[n]='\0';
	clrscr();
	printf("This is a char permutation program!\nPlease input a string:\n");
	scanf("%s",s);
	puts("\nPlease input the char number of permuted:\n");
	scanf("%d",&n);
	puts("The permuted chars are:\n");
	perm(n,s);
	puts("\nPress any key to quit...");
	getch();
}
开发者ID:13436120,项目名称:Cgames,代码行数:15,代码来源:30.c

示例6: char

void crypt::encrypt(char *nachr, int decr)
   {
   char(*schl)[KS] = decr ? schluessel + 15 : schluessel;
   char tmp[BS];
   int i;

   perm(tmp, nachr, IP, BS);

   for (i = 8; i--;)
      {
      crypt_main(tmp, tmp + BS2, *schl);
      if (decr)
         schl--;
      else
         schl++;
      crypt_main(tmp + BS2, tmp, *schl);
      if (decr)
         schl--;
      else
         schl++;
      }

   perm(nachr, tmp, EP, BS);
   }
开发者ID:jbresearch,项目名称:simcommsys,代码行数:24,代码来源:crypt.cpp

示例7: perm

 /**
  * @param nums: A list of integers.
  * @return: A list of unique permutations.
  */
 void perm(vector<vector<int> > &res, vector<int> & nums, int k){
     if(k == nums.size() ){
         res.push_back(nums);
         return;
     }
     
     for(int i = k; i < nums.size(); ++i){
         sort(nums.begin() + k, nums.end());
         if(i == k || nums[i] != nums[i - 1]){
         swap(nums[i], nums[k]);
         perm(res, nums, k + 1);
         swap(nums[i], nums[k]);
         }
     }
 }
开发者ID:happyliangkeshu,项目名称:lintcode,代码行数:19,代码来源:含重复元素的全排列.cpp

示例8: new2old

void CNPLCM_CR_Basic_Freq::permute_latent_classes_by_nu(){
	//reorder latent classes increasingly according to nuK. 
	std::vector<int> new2old(par->K), old2new(par->K);
	std::vector<_CNPLCM_CR_Basic_Freq_mypair> s_index(par->K);
	for (int k = 0; k < par->K; k++){
		s_index[k].first = 1.0 - par->nuK[k];
		s_index[k].second = k;
	}
	std::sort(s_index.begin(), s_index.end(), _CNPLCM_CR_Basic_Freq_comparator);
	std::vector<int> perm(K);
	for (int k = 0; k < par->K; k++){
		new2old[k] = s_index[k].second;
	} // new2old[a] == b <=> former b-th element is now a-th element.
	for (int k = 0; k < par->K; k++){
		old2new[ new2old[k] ] = k;
	}
	CParams_NPLCM_CR_Basic_Freq *tmp = new CParams_NPLCM_CR_Basic_Freq(*par);
	//for (int i = 0; i < par->n; i++){
	//	tmp->zI[i] = old2new[ par->zI[i] ];
	//}
	for (int m = 0; m < par->M; m++){
		for (int k = 0; k < par->K; k++){
			tmp->count_zIK[m][k] = par->count_zIK[m][ new2old[k] ];
		}
	}	
	for (int j = 0; j < par->J; j++){
		for (int k = 0; k < par->K; k++){
			tmp->lambdaJK[j][k] = par->lambdaJK[j][ new2old[k] ];
			tmp->aux_JK2[j][k][0] = par->aux_JK2[j][ new2old[k] ][0];
			tmp->aux_JK2[j][k][1] = par->aux_JK2[j][ new2old[k] ][1];
		}
	}
	for (int k = 0; k < par->K; k++){
		tmp->nuK[k] = par->nuK[new2old[k]];
		tmp->log_nuK[k] = par->log_nuK[new2old[k]];
		tmp->countK[k] = par->countK[new2old[k]];
		tmp->count0K[k] = par->count0K[new2old[k]];
	}
	//std::copy(tmp->zI, tmp->zI + par->n, par->zI);
	std::copy(tmp->count_zIK[0], tmp->count_zIK[0] + par->M * par->J, par->count_zIK[0]);
	std::copy(tmp->lambdaJK[0], tmp->lambdaJK[0] + par->J * par->K, par->lambdaJK[0]);
	std::copy(tmp->aux_JK2[0][0], tmp->aux_JK2[0][0] + par->J * par->K * 2, par->aux_JK2[0][0]);
	std::copy(tmp->nuK, tmp->nuK + par->K, par->nuK);
	std::copy(tmp->log_nuK, tmp->log_nuK + par->K, par->log_nuK);
	std::copy(tmp->countK, tmp->countK + par->K, par->countK);
	std::copy(tmp->count0K, tmp->count0K + par->K, par->count0K);
	delete tmp;
}
开发者ID:cran,项目名称:LCMCR,代码行数:48,代码来源:NPLCM_CR_Basic_Freq.cpp

示例9: perm

void perm(int arr[], int l, int n, int k)
{
    int i;

    if (l == k) {
        if (is_magic_square(arr))
            print_square(arr);
        return;
    }

    for (i = l; i < n; i++) {
        swap(&arr[i], &arr[l]);
        perm(arr, l + 1, n, k);
        swap(&arr[i], &arr[l]);
    }
}
开发者ID:hss440,项目名称:algo1,代码行数:16,代码来源:magic_square.c

示例10: reduction

/* lambda reduction (z=Z'*a, Qz=Z'*Q*Z=L'*diag(D)*L) (ref.[1]) ---------------*/
static void reduction(int n, double *L, double *D, double *Z)
{
    int i,j,k;
    double del;

    j=n-2; k=n-2;
    while (j>=0) {
        if (j<=k) for (i=j+1;i<n;i++) gauss(n,L,Z,i,j);
        del=D[j]+L[j+1+j*n]*L[j+1+j*n]*D[j+1];
        if (del+1E-6<D[j+1]) { /* compared considering numerical error */
            perm(n,L,D,j,del,Z);
            k=j; j=n-2;
        }
        else j--;
    }
}
开发者ID:ejconlon,项目名称:libswiftnav,代码行数:17,代码来源:lambda.c

示例11: perm

void perm(int list[], int k, int m) {
    int i;
    if (k >= m) {
        for (i = 0; i < m; i++) {
            printf("%d ", list[i]);
        }
        printf("\n");
        n++;
    } else {
        for (i = k; i < m; i++) {
            swap(&list[k], &list[i]);
            perm(list, k + 1, m);
            swap(&list[k], &list[i]);
        }
    }
}
开发者ID:thomasking1990,项目名称:workspace,代码行数:16,代码来源:test.c

示例12: tdmsPLS

void tdmsPLS(double *x1, double *x2, int *m, double *epsilon, double *pval, double *sN, int *module1, int *module2, int *n1, int *n2, int *p, int *ncom, int *nperm, int *rescaleData, int *symmetrizeScores, int *rescaleScores){
 int i,pvalnum;
 double psN;
 double *px1;
 double *px2;
 double *s1;
 double *s2;
 double *ps1;
 double *ps2;
 int *smod1;
 int *smod2;
 px1=malloc((*n1)*(*p)*sizeof(double));
 px2=malloc((*n2)*(*p)*sizeof(double));
 s1=malloc((*p)*(*p)*sizeof(double));
 s2=malloc((*p)*(*p)*sizeof(double));
 ps1=malloc((*p)*(*p)*sizeof(double));
 ps2=malloc((*p)*(*p)*sizeof(double));
 smod1=malloc((*p)*sizeof(int));
 smod2=malloc((*p)*sizeof(int));
 rplsnet(x1,s1,ncom,n1,p,rescaleData,symmetrizeScores,rescaleScores);
 rplsnet(x2,s2,ncom,n2,p,rescaleData,symmetrizeScores,rescaleScores);
 rgmd(s1,module1,m,epsilon,p);
 rgmd(s2,module2,m,epsilon,p);
 UnionIntersectionStat(module1,module2,sN,p);
 pvalnum=0;
 Rprintf("Starting permutation test:\n");
 for (i=0;i<*nperm;i++){
  Rprintf("permutation %i out of %i\n",i+1,*nperm);
  perm(x1,x2,px1,px2,n1,n2,p);
  rplsnet(px1,ps1,ncom,n1,p,rescaleData,symmetrizeScores,rescaleScores);
  rplsnet(px2,ps2,ncom,n2,p,rescaleData,symmetrizeScores,rescaleScores);
  rgmd(ps1,smod1,m,epsilon,p);
  rgmd(ps2,smod2,m,epsilon,p);
  UnionIntersectionStat(smod1,smod2,&psN,p);  
  if (psN>=*sN)
   pvalnum++;
 }
 *pval=(0.0+pvalnum)/(*nperm);
 free(smod1);
 free(smod2);
 free(s1);
 free(s2);
 free(ps1);
 free(ps2);
 free(px1);
 free(px2);
}
开发者ID:cran,项目名称:dna,代码行数:47,代码来源:tdmsPLS.c

示例13: tdcclassRR

void tdcclassRR(double *x1, double *x2, int *f, int *nf, double *pval, double *dlt, int *n1, int *n2, int *p, double *lambda, int *nperm, int *rescaleData, int *symmetrizeScores, int *rescaleScores, int *distancetype){
 int i,pvalnum;
 double pdlt;
 double *px1;
 double *px2;
 double *s1;
 double *s2;
 double *ps1;
 double *ps2;
 px1=malloc((*n1)*(*p)*sizeof(double));
 px2=malloc((*n2)*(*p)*sizeof(double));
 s1=malloc((*p)*(*p)*sizeof(double));
 s2=malloc((*p)*(*p)*sizeof(double));
 ps1=malloc((*p)*(*p)*sizeof(double));
 ps2=malloc((*p)*(*p)*sizeof(double));
 rrrnet(x1,s1,lambda,n1,p,rescaleData,symmetrizeScores,rescaleScores);
 rrrnet(x2,s2,lambda,n2,p,rescaleData,symmetrizeScores,rescaleScores);
 if (*distancetype==1)
  absDISTclassgenes(s1,s2,f,nf,dlt,p);
 else if (*distancetype==2)
  sqrDISTclassgenes(s1,s2,f,nf,dlt,p);
 (*dlt)/=*nf;
 (*dlt)/=(*nf)-1.0;
 pvalnum=0;
 Rprintf("Starting permutation test:\n");
 for (i=0;i<*nperm;i++){
  Rprintf("permutation %i out of %i\n",i+1,*nperm);
  perm(x1,x2,px1,px2,n1,n2,p);
  rrrnet(px1,ps1,lambda,n1,p,rescaleData,symmetrizeScores,rescaleScores);
  rrrnet(px2,ps2,lambda,n2,p,rescaleData,symmetrizeScores,rescaleScores);
  if (*distancetype==1)
   absDISTclassgenes(ps1,ps2,f,nf,&pdlt,p);
  else if (*distancetype==2)
   sqrDISTclassgenes(ps1,ps2,f,nf,&pdlt,p);
  pdlt/=*nf;
  pdlt/=(*nf)-1.0;
  if (pdlt>=*dlt)
   pvalnum++;
 }
 *pval=(0.0+pvalnum)/(*nperm);
 free(s1);
 free(s2);
 free(ps1);
 free(ps2);
 free(px1);
 free(px2);
}
开发者ID:cran,项目名称:dna,代码行数:47,代码来源:tdcclassRR.c

示例14: mesh_node_extractor

void ModifyMeshProperties::substituteMaterialID (GEOLIB::Polygon const& polygon, size_t old_mat_id, size_t new_mat_id)
{
    MeshLib::ExtractMeshNodes mesh_node_extractor(_mesh);
    std::vector<size_t> mesh_node_ids;
    mesh_node_extractor.getMeshNodeIDsWithinPolygon(polygon, mesh_node_ids);
    const size_t n_mesh_node_ids(mesh_node_ids.size());
    std::vector<size_t> perm(n_mesh_node_ids);
    // init permutation for sorting
    for (size_t k(0); k<n_mesh_node_ids; k++) perm[k] = k;
    // sort - since we want to use binary search
    Quicksort<size_t> (mesh_node_ids, 0, n_mesh_node_ids, perm);

//#ifndef NDEBUG
//	std::ofstream test_out ("Points.gli");
//	test_out << "#POINTS" << std::endl;
//	FileIO::OGSMeshIO mesh_io;
//	mesh_io.setMesh(_mesh);
//	mesh_io.writeMeshNodesAsGLIPnts(mesh_node_ids, test_out);
//	test_out << "#STOP" << std::endl;
//#endif

    // get all nodes of the mesh
    const std::vector<MeshLib::CNode*>& mesh_nodes (_mesh->getNodeVector());
    // get all elements of the mesh
    const std::vector<MeshLib::CElem*>& mesh_elements (_mesh->getElementVector());

    for (size_t k(0); k<n_mesh_node_ids; k++) {
        std::vector<size_t> const& connected_element_ids (mesh_nodes[mesh_node_ids[k]]->getConnectedElementIDs());
        for (size_t j(0); j<connected_element_ids.size(); j++) {
            if(mesh_elements[connected_element_ids[j]]->GetPatchIndex() == old_mat_id) {
                std::vector<size_t> connected_nodes;
                // check if all nodes of element are in the mesh_node_ids vector
                mesh_elements[connected_element_ids[j]]->getNodeIndices(connected_nodes);
                bool all_found(true);
                const size_t n_connected_nodes(connected_nodes.size());
                for (size_t i(0); i<n_connected_nodes && all_found; i++) {
                    if (searchElement(connected_nodes[i], 0, n_mesh_node_ids, mesh_node_ids) == std::numeric_limits<size_t>::max()) {
                        all_found = false;
                    }
                }
                if (all_found) {
                    mesh_elements[connected_element_ids[j]]->setPatchIndex(new_mat_id);
                }
            }
        }
    }
}
开发者ID:norihiro-w,项目名称:ogs5,代码行数:47,代码来源:ModifyMeshProperties.cpp

示例15: main

 int main(){ 
 
  int N = strlen(list);

  long  F = factorial( N );

 

  printf( "\n문자열 \'%s\'을 나열하는 경우의 수는 %d!(=%ld)입니다.\n", list,  N, F  );
  printf( "그 모든 경우는 아래와 같습니다.\n\n");

  perm( list, 0, N-1 ); 


  getch(); 
  return 0;
} 
开发者ID:yebgi83,项目名称:Old-Works,代码行数:17,代码来源:main.cpp


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