• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ perm函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: perm

void perm(int *A, int k, int n, int depth)
{
  int i = 0;
  int B[ELEMENTS] = {0};

  assign(B, A);

  for(i=k;i<n;i++)
  {
    swap(&A[k], &A[i]);
    if(k==depth)
      print(A, k+1);
    else
      perm(A, k+1, n, depth);
    assign(A, B);
  }
}
开发者ID:IMCG,项目名称:cpptruths,代码行数:17,代码来源:permutations.c


示例17: main

int main(int argc,char *argv[]) {
    int n=2;
    char s[N];
    w[n]='\0';

    puts("This is a char permutation program!");
    puts("Please input a string:");
    scanf("%s",s);
    puts("Please input the char number of permuted:");
    scanf("%d",&n);
    puts("The permuted chars are:");
    perm(n,s);

    puts("\nPress any key to quit...");
    getch();
    return 0;
}
开发者ID:lovexy-W,项目名称:SomeCodes,代码行数:17,代码来源:29.c


示例18: test_evaluator

void test_evaluator(const Interface& g)
{
    typedef typename Interface::CellIterator CI;
    typedef typename CI       ::FaceIterator FI;
    typedef typename CI       ::Scalar       Scalar;

    typedef Dune::SharedFortranMatrix FMat;

    std::cout << "Called test_evaluator()" << std::endl;

    std::vector<int> numf; numf.reserve(g.numberOfCells());
    int max_nf = -1;
    for (CI c = g.cellbegin(); c != g.cellend(); ++c) {
        numf.push_back(0);
        int& nf = numf.back();

        for (FI f = c->facebegin(); f != c->faceend(); ++f)
            ++nf;

        max_nf = std::max(max_nf, nf);
    }

    typedef int DummyClass;
    Dune::MimeticIPEvaluator<Interface, DummyClass> ip(max_nf);

    // Set dummy permeability K=diag(10,1,...,1,0.1).
    std::vector<Scalar> perm(dim * dim, Scalar(0.0));
    Dune::SharedCMatrix K(dim, dim, &perm[0]);
    for (int i = 0; i < dim; ++i)
        K(i,i) = 1.0;
    K(0    ,0    ) *= 10.0;
    K(dim-1,dim-1) /= 10.0;

    // Storage for inverse ip.
    std::vector<Scalar> ip_store(max_nf * max_nf, Scalar(0.0));

    // Loop grid whilst building (and outputing) the inverse IP matrix.
    int count = 0;
    for (CI c = g.cellbegin(); c != g.cellend(); ++c, ++count) {
        FMat Binv(numf[count], numf[count], &ip_store[0]);

        ip.evaluate(c, K, Binv);

        std::cout << count << " -> Binv = [\n" << Binv << "]\n";
    }
}
开发者ID:hnil,项目名称:opm-porsol,代码行数:46,代码来源:mimetic_ipeval_test.cpp


示例19: myselect

void myselect(char* str, int len, char* result, int start, int curr, int dest) 
{ 
    if (curr == dest) 
    { 
        //    puts(result); 
        perm(result, 3, 0); 
    } 
    else 
    { 
        int i; 
        for (i = start; curr + len - i >= dest; ++i) 
        { 
            result[curr] = str[i]; 
            myselect(str, len, result, i+1, curr+1, dest); 
        } 
    } 
} 
开发者ID:ZhangZhenhua,项目名称:experiment-coding,代码行数:17,代码来源:mn.c


示例20: LOG

void Graph::sort_edges(std::string order) {

  if (order == HILBERT) {
    VidType nv = (VidType)get_n_vertices();
    LOG(INFO) << " Graph::nv = " << nv;
    VidType max_n = 2;
    while ( nv >>=1 ) {
      max_n <<= 1;
    }

    LOG(INFO) << " HilbertOrder::max_n = " << max_n;
    HilbertOrder::set_maxn(max_n);
    //HilbertOrder::set_maxn(MAX_BIT);

    //std::sort(edges.begin(), edges.end(), HilbertOrder());
    // get permutation
    
    size_t ne = edges.size();
    std::vector<int64_t> d(ne);
    for(size_t i = 0;i < ne;i ++) {
      d[i] = HilbertOrder::get_d(edges[i].src, edges[i].dst);
    }

    std::vector<size_t> perm(ne);
    for(size_t i = 0;i < ne;i ++) {
      perm[i] = i;
    }

    std::sort(perm.begin(), perm.end(), 
              [&](const size_t & A, const size_t &B) {
                return d[A] < d[B];
              });

    d.resize(0);
    // sort
    size_t flag = 0;
    size_t cnt = 0;

    std::vector<Edge> edge_copy(edges);
    for(size_t i = 0;i < ne;i ++) {
      edges[i] = edge_copy[perm[i]];  
    }
    edge_copy.resize(0);

  } else if (order == DST ) {
开发者ID:zorksylar,项目名称:pagerank,代码行数:45,代码来源:graph.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ permute函数代码示例发布时间:2022-05-30
下一篇:
C++ perl_parse函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap