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


C++ bitset类代码示例

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


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

示例1: GetParam

int ParseCNC::GetParam(string cmd1, vector<string>::iterator & it, const cmdlist& cmdlst, vector<string> & params, bitset<16> & paramsChanged)
{

	it++;
	string param;
	paramsChanged = 0;
	vector<string> vparams(_gCodeParam.size(),"0.0");
	while (it != cmdlst.end())
	{
		for (map <int, string>::const_iterator itGparam=_gCodeParam.begin(); itGparam != _gCodeParam.end(); itGparam++)
		{
			if (ParseData(it, itGparam->second, 0, cmdlst, param))
			{
				it++;
				vparams[itGparam->first]=param;
			    switch (itGparam->first)
				{
					case 0:  
						{
							paramsChanged.set(gXAxisbit, true);
						}
						break;
					case 1:  
						{
							paramsChanged.set(gYAxisbit, true);
						}
						break;
					case 2:  
						{
							paramsChanged.set(gZAxisbit, true);
						}
						break;
					case 3:  
						{
							paramsChanged.set(gFeedbit, true);
						}
						break;
					case 4:  
						{
							paramsChanged.set(gIAxisbit, true);
						}
						break;
					case 5:  
						{
							paramsChanged.set(gJAxisbit, true);
						}
						break;
					case 6:  
						{
							paramsChanged.set(gKAxisbit, true);
						}
						break;
					default:
						{
						}

				};

			}
		}
	}
	params=vparams;
	return 0;
}
开发者ID:duchiy,项目名称:CNCMillwithGCodeInterpreter,代码行数:64,代码来源:ParseCNC.cpp

示例2: substitution

string MsgEnc:: substitution(bitset<6> B,int count)
{
	int s1[4][16]=
	{
		14,4,13,1,2,15,11,8,3,10,6,12,5,9,0,7,
		0,15,7,4,14,2,13,1,10,6,12,11,9,5,3,8,
		4,1,14,8,13,6,2,11,15,12,9,7,3,10,5,0,
		15,12,8,2,4,9,1,7,5,11,3,14,10,0,6,13
	};

	int s2[4][16]=
	{
		15,1,8,14,6,11,3,4,9,7,2,13,12,0,5,10,
		3,13,4,7,15,2,8,14,12,0,1,10,6,9,11,5,
		0,14,7,11,10,4,13,1,5,8,12,6,9,3,2,15,
		13,8,10,1,3,15,4,2,11,6,7,12,0,5,14,9
	};

	int s3[4][16]=
	{
		10,0,9,14,6,3,15,5,1,13,12,7,11,4,2,8,
		13,7,0,9,3,4,6,10,2,8,5,14,12,11,15,1,
		13,6,4,9,8,15,3,0,11,1,2,12,5,10,14,7,
		1,10,13,0,6,9,8,7,4,15,14,3,11,5,2,12
	};

	int s4[4][16]=
	{
		7,13,14,3,0,6,9,10,1,2,8,5,11,12,4,15,
		13,8,11,5,6,15,0,3,4,7,2,12,1,10,14,9,
		10,6,9,0,12,11,7,13,15,1,3,14,5,2,8,4,
		3,15,0,6,10,1,13,8,9,4,5,11,12,7,2,14
	};

	int s5[4][16]=
	{
		2,12,4,1,7,10,11,6,8,5,3,15,13,0,14,9,
		14,11,2,12,4,7,13,1,5,0,15,10,3,9,8,6,
		4,2,1,11,10,13,7,8,15,9,12,5,6,3,0,14,
		11,8,12,7,1,14,2,13,6,15,0,9,10,4,5,3
	};

	int s6[4][16]=
	{
		12,1,10,15,9,2,6,8,0,13,3,4,14,7,5,11,
		10,15,4,2,7,12,9,5,6,1,13,14,0,11,3,8,
		9,14,15,5,2,8,12,3,7,0,4,10,1,13,11,6,
		4,3,2,12,9,5,15,10,11,14,1,7,6,0,8,13
	};

	int s7[4][16]=
	{
		4,11,2,14,15,0,8,13,3,12,9,7,5,10,6,1,
		13,0,11,7,4,9,1,10,14,3,5,12,2,15,8,6,
		1,4,11,13,12,3,7,14,10,15,6,8,0,5,9,2,
		6,11,13,8,1,4,10,7,9,5,0,15,14,2,3,12
	};

	int s8[4][16]=
	{
		13,2,8,4,6,15,11,1,10,9,3,14,5,0,12,7,
		1,15,13,8,10,3,7,4,12,5,6,11,0,14,9,2,
		7,11,4,1,9,12,14,2,0,6,10,13,15,3,5,8,
		2,1,14,7,4,10,8,13,15,12,9,0,3,5,6,11
	};
	int l_r,l_res,l_c;
	string l_temp,l_bc,l_result;
	if(B[5] == 0 && B[0] == 0)
		l_r = 0;
	else if(B[5] == 0 && B[0] == 1)
		l_r = 1;
	else if(B[5] == 1 && B[0] == 0)
		l_r = 2;
	else
		l_r = 3;
	l_temp = B.to_string();
	l_bc =l_temp.substr(1,4);
	l_c=BintoNum(l_bc);
	l_temp.clear();
	l_bc.clear();
	switch(count)
	{
	case 1:
		l_res = s1[l_r][l_c];
		break;
	case 2:
		l_res = s2[l_r][l_c];
		break;
	case 3:
		l_res = s3[l_r][l_c];
		break;
	case 4:
		l_res = s4[l_r][l_c];
		break;
	case 5:
		l_res = s5[l_r][l_c];
		break;
	case 6:
		l_res = s6[l_r][l_c];
		break;
//.........这里部分代码省略.........
开发者ID:sarvani13,项目名称:Source,代码行数:101,代码来源:Server_main.cpp

示例3: find_best_split

void cart::find_best_split(vector<const sample*>& samples,
                          const bitset& splitted_features,
                          tree_node_split& best_split)
{
     /*for each feature f not set in splitted_features
          for each splittable value s of feature f
              R1 = {samples whose feature f's value is smaller than s}
              R2 = {samples whose feature f's value is not smaller than s}
              calculate the cost
                  C = sum{(y1 - c1)^2} + sum{(y2 - c2)^2}
              c1 = mean(y) in R1, c2 = mean(y) in R2
       find (f,s) with mininum C
     */
     //for each feature f
     //  sort samples by f's value
     //  scan samples in ascending order of f's value
     //  for splittable value s
     //  C = sum(y1 ^ 2) + sum(c1 ^ 2) - 2 * c1 * sum(y1) + sum(y2 ^ 2) + sum(c2 ^ 2) - 2 * c2 * sum(y2)
     //  C = CL + CR
     //  c1 = sum(y1) / |CL|
     //  c2 = sum(y2) / |CR|
     //  CL = CLY2 + CLC2 - 2 * c1 * CLY
     //  CR = CRY2 + CRC2 - 2 * c2 * CRY
    double min_ds = -1;
    best_split.fid = splitted_features.size();
    best_split.val = FLT_MIN;
    for (size_t fid = 0; fid < splitted_features.size(); fid++)
    {
        if (splitted_features.test(fid))
        {
            continue;
        }
        //sort samples by feature fid
        feature_comp fcmp(fid);
        std::sort(samples.begin(), samples.end(), fcmp);
        double square_cy1, square_cy2, sum_y1, sum_y2, my1, my2, ds1, ds2;
        size_t ny1, ny2;
        square_cy1 = square_cy2 = sum_y1 = sum_y2 = ny1 = ny2 = my1 = my2 = ds1 = ds2 = 0;
        for (vector<const sample*>::iterator it = samples.begin(); it != samples.end(); it++)
        {
           const sample* sa = *it;
           square_cy2 += sa->y * sa->y;
           sum_y2 += sa->y;
           ny2++;
        }
        for (vector<const sample*>::iterator it = samples.begin(); it != samples.end(); it++)
        {
           const sample* sa = *it;
           //each sample's value is a split value
           square_cy1 += sa->y * sa->y;
           ny1++;
           sum_y1 += sa->y;
           my1 = sum_y1 / ny1;
           ds1 = square_cy1 + my1 * my1 * ny1 - 2 * my1 * sum_y1;
           square_cy2 -= sa->y * sa->y;
           ny2--;
           sum_y2 -= sa->y;
           my2 = sum_y2 / ny2;
           ds2 = square_cy2 + my2 * my2 * ny2 - 2 * my2 * sum_y2;
           if (min_ds < 0 || min_ds > ds1 + ds2)
           {
               min_ds = ds1 + ds2;
               best_split.fid = fid;
               best_split.val = sa->x[fid];
           }
        }
    }
}
开发者ID:king821221,项目名称:coding,代码行数:68,代码来源:cart.cpp

示例4: main

int main()
{
	int NUM=sqrt(MAX),n;
	arr.reset();
	arr[0]=1;
	arr[1]=1;
	
	for(int i=4;i<MAX;i+=2)
		arr.set(i,true);
		
	for(int i=9;i<MAX;i+=6)
		arr.set(i,true);		

	
	for(int i=0;i<SIZE;i++)
			val[i]=0;	
		
	val[0]=2;
	
	bool flag=true;
	
	int i;
	
	for(i=5;i<NUM;)
	{
		int k=i/5;
		
		if(!val[k])
			val[k]=val[k-1];
			
		if(!arr.test(i))
		{
			val[k]++;		
			mark_all(i);
		}
		
		if(flag)
		{
			flag=0;
			i+=2;
		}
		
		else
		{
			flag=1;
			i+=4;
		}
	}
	
	for(;i<MAX;)
	{
		int k=i/5;
		if(!val[k])
			val[k]=val[k-1];
			
		if(!arr.test(i))
			val[k]++;		
		
		if(flag)
		{
			flag=0;
			i+=2;
		}
		
		else
		{
			flag=1;
			i+=4;
		}
	}
	
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			return 0;
			
		float calc=0;
		int num=n/5-1;
		
		if(num>=0)
			calc=val[num];
		
		for(int i=5*(num+1);i<=n;i++)
				if(!arr.test(i))
					calc++;
		
		cout<<calc<<"\n";
		
		printf("%0.1f\n",abs((float)calc - (float)(n/log(n)))/(float)calc *100);
	}
}
开发者ID:abhinavaggarwal018,项目名称:C--,代码行数:92,代码来源:CPRIME2.cpp

示例5: is_sieve_prime

bool is_sieve_prime(int num)
{
	if( num < 2) 
		return false;
	return !prime.test(num);
}
开发者ID:rahulroot,项目名称:Uva,代码行数:6,代码来源:program.cpp

示例6: mark_all

void mark_all(int i)
{
	for(int j=i*i;j<MAX;j=j+i+i)
		arr.set(j,true);
}
开发者ID:abhinavaggarwal018,项目名称:C--,代码行数:5,代码来源:CPRIME2.cpp

示例7: main

int main()
{
  int t,c;
  int a,b;
  c = 0;
  scanf("%d",&t);
  while( t-- )
  {
    memset( ff , -1 , sizeof ff );
    scanf("%d %d",&n ,&r);
    for( int i = 0 ; i < n ; ++i )
      for( int j = 0 ; j < n ; ++j )
      {
        if( j == i )
          graph[ i ][ j ] = 0;
        else
          graph[ i ][ j ] = INF;
        path[ i ][ j ] = j;
      }
    for( int  i = 0 ; i < r  ; ++i )
    {
      scanf("%d %d",&a,&b);
      graph[ a ][ b ] = min(1,graph[a][b]);
      graph[ b ][ a ] = min(1,graph[b][a]);
    }
    scanf("%d %d",&a,&b );
    floyd();
    visited.reset();
    int totW = 0;
    // cout << a << " " << b << " " << graph[ a ][ b ] << endl;
    totW += graph[ a ][ b ];
    fres = true;
    res.clear();
    re( a , b  );
    fres = false;
    /*
    // cout << a <<  " "<< b << endl;
    // cout << "hola" << endl;
    int may = -1, tt = 0;
    for( int i = 0 ; i < n ; ++i )
    {
      temp = i;
      if( ! visited[ i ] )
      {

        temp = re( i , b );
      // cout << temp << endl;
      // totW += 2*graph[ i ][ temp ];
      // ff[ temp ] = max( ff[ temp ] , 2*graph[ i ][ temp ] );
      // may = max( may , graph[ i ][ temp ] + min(graph[ i ][ temp ] , graph[ i ][ b ] ) );
        tt = graph[ i ][ b ] - graph[ temp ][ b ];
        if ( tt < 0 )
          tt = 0;
        cout << "hk "<< tt << " i " << i  << " " << graph[ i ][ b ] << " " << graph[ temp ][ b ] << " temp " << temp<< endl;
        may = max( may , graph[ i ][ temp ] + ( min ( graph[ i ][ temp ] , tt )));
      }
      // cout << totW << endl;
    }
    */
    int may = 0, temp = 0  ;
    for( int i = 0; i < n ; ++i )
    {
      if( !visited[ i ] )
      {
        temp = INF;
        for( int j = 0 ; j < res.size() ; ++j )
        {
          int tt ;
          tt = graph[ i ][ b ] - graph[ res[ j ] ][ b ];
          if( tt < 0 )
            tt = 0;
          temp = min( temp , graph[ i ][ res[ j ] ] + min( graph[ i ][ res [ j ] ] , tt ));
        }
        may = max( may , temp );
      }
      // cout << "llegue" << endl;
    }
    totW += may;
    printf("Case %d: %d\n",++c,totW );
  }
  return 0;
}
开发者ID:johan-smc,项目名称:UVA,代码行数:82,代码来源:11463.cpp

示例8: uncross

	void uncross(unsigned int num) {
		marked.reset(idx(num));
	}
开发者ID:Crazygolem,项目名称:epfl,代码行数:3,代码来源:Range.cpp

示例9: init

void init(){
	isprime.reset();
	isprime[2] = isprime[3] = isprime[5] = isprime[7] = isprime[11] = isprime[13]= isprime[17] = isprime[19] = isprime[23] = isprime[29] = isprime[31] = 1;
}
开发者ID:Pedrotok,项目名称:competitive_prog,代码行数:4,代码来源:00524.cpp

示例10: isMarked

	bool isMarked(unsigned int num) {
		return marked.test(idx(num));
	}
开发者ID:Crazygolem,项目名称:epfl,代码行数:3,代码来源:Range.cpp

示例11: cross

	void cross(unsigned int num) {
		marked.set(idx(num));
	}
开发者ID:Crazygolem,项目名称:epfl,代码行数:3,代码来源:Range.cpp

示例12: Initialize

 void Initialize() {
     flags.set(this->f_GroundTile);
 }
开发者ID:redheru,项目名称:CodeChunk,代码行数:3,代码来源:GLUTBase.hpp

示例13: main

int main()
{
    int p1,p2,p3,p4,p5,p6,n=0,ti,s1,s2,s3,s4,s5;
    for(p6=0;p6<10;++p6){for(p5=0;p5<10;++p5){s1=p5+p6;for(p4=0;p4<10;++p4){s2=s1+p4;for(p3=0;p3<10;++p3){s3=s2+p3;for(p2=0;p2<10;++p2){s4=p2+s3;for(p1=0;p1<10;++p1){s5=s4+p1;ti=s5+n;if(ti<MAXN){bs.set(ti);}++n;}}}}}}for(p1=1;p1<MAXN;++p1){if(!bs.test(p1)){printf("%d\n",p1);}}return 0;}
开发者ID:vijaynitrr,项目名称:Spoj,代码行数:4,代码来源:MCUR98.cpp

示例14: isPrime

bool isPrime(ll n){

	if(n < MAX) return bs.test(n);
	for(ll i = 0; i <primes.size(); i++) if (n % primes[i] == 0) return false;
	return true;
} 
开发者ID:mari-linhares,项目名称:Programming,代码行数:6,代码来源:code.cpp

示例15: main

int main()
{
    //freopen("C:/Users/DR. MOON GUPTA/Desktop/Deepak/Programs/Spoj/Text/POSTERS.txt","r",stdin);

    int i,j,cases,x1,y1,x2,y2,x3,y3,x,y,z1,z2,z3;

    scanf("%d",&cases);

    while(cases--)
    {
        countt=0;
        bb.reset();
        wall.clear();
        scanf("%d",&n);

        scanf("%d %d",&x,&y);
        wall.insert(piii(pii(x,y),1));

        for(i=2;i<=n;++i)
        {
            x1=y1=x2=y2=x3=y3=z1=z2=z3=-1;

            scanf("%d %d",&x,&y);

            st=wall.upper_bound(piii(pii(x,x),0));
            en=wall.upper_bound(piii(pii(y,y),0));
            z2=i;


            if(en==wall.begin())
            {
                x2=x;
                y2=y;
            }
            else if(st==wall.begin())
            {
                --en;

                x2=x;
                y2=y;

                if(en->fs>y)
                {
                    x3=en->fs+1;
                    y3=y;
                    z3=en->second;
                }

                wall.erase(st,en);
            }
            else if(st==en)
            {
                --st;
                --en;

                if(st->ff<x && st->fs>y)
                {
                    x1=st->ff;
                    y1=x-1;
                    z1=st->second;

                    x2=x;
                    y2=y;

                    x3=y+1;
                    y3=st->fs;
                    z3=st->second;

                    ++en;
                    wall.erase(st,en);
                }
                else if(st->ff==x && st->fs<=y)
                {
                    x2=x;
                    y2=y;

                    ++en;
                    wall.erase(st,en);
                }
                else if(st->ff<x && st->fs<=y)
                {
                    x1=st->ff;
                    y1=x-1;
                    z1=st->second;

                    x2=x;
                    y2=y;

                    ++en;
                    wall.erase(st,en);
                }
                else if(st->ff==x && st->fs>y)
                {
                    x2=x;
                    y2=y;

                    x3=y+1;
                    y3=st->fs;
                    z3=st->second;

//.........这里部分代码省略.........
开发者ID:vijaynitrr,项目名称:Spoj,代码行数:101,代码来源:POSTERS.cpp


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