Exemple #1
0
int main()
{
    freopen("milk3.in","r",stdin);
    freopen("milk3.out","w",stdout);
    
    for (int i = 0; i < 3; ++i)
         cin>>cap[i];
    
    int init[3];
    init[0] = init[1] = 0;
    init[2] = cap[2];
    dfs(init);

    int space_num = ans.count() - 1;
    for (int i = 0; i < 21; ++i)
    {
        if( ans.test(i) && space_num )
        {
            cout<<i<<" ";
            space_num--;
        }
        else if(ans.test(i))
            cout<<i<<endl;
    }
    
    return 0;	  
}
Exemple #2
0
bool hasConflict(int n, int m, vector<int> &s, vector<int> &e, vector<int> &r)
{
    // One-time tasks.
    for (int i = 0; i < n; ++i)
    {
        int start = s[i], end = e[i];
        // "Touching" is OK, so check from start + 1.
        for (int t = start + 1; t <= end; ++t)
        {
            if (schedule.test(t))
                return true;
            else
                schedule.set(t);
        }
    }
    // Repeating tasks.
    for (int i = n; i < n + m; ++i)
    {
        int start = s[i], end = e[i], interval = r[i];
        while (start < 1000000)
        {
            for (int t = start + 1; t <= end; ++t)
            {
                if (schedule.test(t))
                    return true;
                else
                    schedule.set(t);
            }
            start += interval;
            end = min(end + interval, 1000000);
        }
    }
    return false;
}
void ParseCNC::CalculateXYZ(double x0, double y0, double z0, bitset<16> changedxyz, double & x1, double & y1, double & z1 )
{
	double x,y,z;
	_lastPosition.Get(x, y, z);

	if (changedxyz.test(0))
	{
		x1=x0;
	}
	else
	{
		x1=x;
	}

	if (changedxyz.test(1))
	{
		y1=y0;
	}
	else
	{
		y1=y;
	}

	if (changedxyz.test(2))
	{
		z1=z0;
	}
	else
	{
		z1=z;
	}
		
}
Exemple #4
0
void sieve()
{
    int sq=sqrt(MAXN);

    for(int i=3;i<=sq;i+=2)
    {
        if(!bs.test(i))
        {
            for(int j=i*i;j<MAXN;j+=i)
            {
                bs.set(j);
            }
        }
    }

    primes.PB(2);

    for(int i=3;i<MAXN;i+=2)
    {
        if(!bs.test(i))
        {
            primes.PB(i);
        }
    }

    plen=primes.size();


}
Exemple #5
0
void dfs(int nowlen,int laststr){
	int rest=f.count();
	if(nowlen+rest>=anslen)
		return;
	if(!rest){
		memcpy(ans,now,sizeof(now));
		anslen=nowlen; return;
	}
	static const int z=pow(c,l-1);
	int newstr=(laststr%z)*c;
	if(nowlen<l-1){
		for(int k=0;k<c;++k,++newstr)
			now[nowlen]=k,dfs(nowlen+1,newstr);
		return;
	}
	for(int k=0;k<c;++k,++newstr)	
		if(f.test(newstr)){
			now[nowlen]=k;	
			f.reset(newstr);
			dfs(nowlen+1,newstr);
			f.set(newstr);
		}
	newstr=(laststr%z)*c;
	for(int k=0;k<c;++k,++newstr)
		if(!f.test(newstr))
			now[nowlen]=k,dfs(nowlen+1,newstr);
}
int main() {
    //Get primes
    sieve.set();
    sieve[0] = sieve[1] = 0;
    for(int i=4;i<MAXM;i+=2)
        sieve.reset(i);
    primes.emplace_back(2);
    for(int i=3;i*i<=MAXN;i+=2)
        if(sieve.test(i))
            for(int j=i*i;j<MAXN;j+=i)
                sieve.reset(j);
    //Push into vector
    for(int i=3;i<MAXN;i+=2)
        if(sieve[i])
            primes.emplace_back(i);
    scanf("%d%d", &N, &M);
    for(int i=1;i<=M;i++)
        scanf("%d", cost + i);
    dp[0][0] = 1;
    for(int i=1;i<=M;i++)
        for(int p:primes)
            for(int j=p*cost[i];j<MAXN;j++)
                if(dp[i-1][j-p*cost[i]])
                    dp[i].set(j);
    for(int p:primes) {
        if(p > N) break;
        if(dp[M][p])
            return puts("its primetime"), 0;
    }
    puts("not primetime");
}
Exemple #7
0
    template<class V> void print_container(V& container, bitset<MAX_BITS_SIZE>& flag, bool reverse, bool is_servercmp)
    {
      if (reverse)
      {
        flag.flip();
      }
      typename V::iterator it = container.begin();

      if (!is_servercmp) // print different block
      {
        int32_t count = static_cast<int32_t> (flag.count());
        for (int32_t i = 0, c=0; (it != container.end()) && (count > 0); i++, it++)
        {
          if (flag.test(i))
          {
            cout << *it ;
            if((++c) % 20 == 0)
              cout<<"\n";
            else
              cout<<" ";
            count--;
          }
        }
        printf(" [%d]\n", static_cast<int32_t>((flag.count() - count)));
      }
      else
      {
        for (int32_t i = 0; it != container.end(); i++, it++)
        {
          printf("%23s%c", tbsys::CNetUtil::addrToString(*it).c_str(),
              suffix(flag[i]));
        }
        printf(" [%zd]\n", container.size());
      }
    }
bool isPrime(LL n)
{
   if(bset.test(n))
    return true;
    else 
    return false;
}
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    sieveGen();
    int test, up;
    long long int m, n, x;
    scanf("%d", &test);
    while( test-- ) {
        scanf("%lld %lld", &m, &n);
        up = upper_bound(pl.begin(), pl.end(), sqrt(n)) - pl.begin();
        if(up == pl.size() ) up--;
        ans.set();
        for(int k = 0; k <= up; k++ ) {
            x = (m / pl[k])*pl[k];
            if(x <= pl[k]) x = pl[k] + pl[k];
            for(x; x <=n ; x += pl[k] ) {
                if(x - m < 0)continue;
                ans.reset(x - m);
            }
        }
        if( m == 1)ans.reset(0);
        for(int k = 0; k <= n - m; k++ ) {
            if(ans.test(k))printf("%lld\n", k+m);
        }
        if(test)puts("");
    }
    return 0;
}
i64 analysis_history(i64 num, vector<int>& candidates, vector<int>& vselect, vector<vector<int> >& vexp, bitset<61>& hi)
{
    i64 prod = 1;
    i64 root = sqrt(num);
    vector<int> sel_exps;
    sel_exps.resize(vexp[0].size(), 0);

    for(unsigned int i = 0; i<vexp[0].size(); ++i){
        if(hi.test(i)) {
            int index = vselect[i];
            prod *= (root-sieve_interval+vselect[i]);
            prod %= num;
            for(unsigned int j = 0; j < vexp[index].size(); ++j){
                sel_exps[j] += vexp[index][j];
            }
        }
    }
    i64 prod2 = 1;
    assert(sel_exps.size() == candidates.size()+1);
    for(unsigned int i = 1; i < sel_exps.size(); ++i){
        assert(sel_exps[i] % 2 == 0);
        prod2 *= power(primes[candidates[i-1]], sel_exps[i]/2);
        prod2 %= num;
    }
    i64 delta = prod>prod2?prod-prod2:prod2-prod;
    i64 ret = gcd(delta, num);
    return ret;
}
Exemple #11
0
void load_primer_table2() {
 
  int i, j;
 
  for(i = 1; i <= MAX; i++) {
 
    if( i % 2) {
		mybs.set(i-1);
		//cout<<i<<" is prime"<<endl;
    } else { 
      mybs.reset(i-1); 
    } 
  } 

  //leave only odd value
  //but 1 should be removed
  // and 2 should be set
  mybs.reset(0);
  mybs.set(1);
  cout<<mybs<<endl;
  
  int upper = sqrt(MAX);
 
  for(i = 2; i <= upper; i++) {
    if(mybs.test(i-1)) { 
      for(j = i + i; j < MAX; j += i) 
        mybs.reset(j-1); 
    } 
  }
  
  cout<<mybs<<endl;
 }
Exemple #12
0
int main() {
    v.set();
    v.reset(1);
    v.reset(0);
    for (int i = 2; i < N; i++)
        for (int j = i + i; j <= N; j += i)
            v.reset(j);
    rep (i, N) if (v.test(i)) a.push_back(i);
    int cnt = 0;
    int l, r;
    scanf("%d%d", &l, &r);
    bool first = 0;
    for (int i = l; i <= r; i++) {
        if (!i) continue;
        ++cnt;
        if (first) {
            if (cnt == 11) {
                cnt = 1;
                printf("\n");
            } else {
                printf(" ");
            }
        }
        first = 1;
        printf("%d", a[i - 1]);
    }
    return 0;
}
Exemple #13
0
void init() {
	for (ll i=2; i<MAXN; ++i) if (!v.test(i)) {
		p[c++] = i;
		for (ll j=i*i; j<MAXN; j+=i) v.set(j);
	}
	pp[0] = p[0];
	for (int i=1; i<c; ++i) pp[i] = pp[i-1] * p[i];
}
Exemple #14
0
bool isPrimeUtil(ll N,bitset<100007>&_bitset,vector<int>&primes){
    if(N < (int)_bitset.size())
        return _bitset.test(N);
    for(ll i=0; i<primes.size();i++)
        if(N%primes[i]==0)
            return false;
    return true;
}
void setPrimes()
{
    bset.reset();
    bset.flip();
    bset[1]=0;

    for (size_t i=2;i<LIMIT;i++)
        if (bset.test(i))
             for (size_t j=2; j*i<LIMIT; j++ )
                bset[j*i]=0;
    
    for(LL i=2;i<LIMIT;i++)
        if(bset.test(i))
            primes.push_back(i);
  

}
Exemple #16
0
int main(){
	ios_base::sync_with_stdio(false);
	
	cin >> T;
	while(T--){
		cin >> N >> M;
		memset(p,-1,sizeof p); memset(colors, WHITE, sizeof colors);
		visited.reset(); children.clear();
		whites.clear();
		int x;
		whites.insert(0);
		for(int i = 1; i < N; i++){
			cin >> x;
			p[i] = --x;
			children[x].push_back(i);
			whites.insert(i);
		}
		
		
		buildRMQ();
		
		RMQ();
		
		int lca, dist, dist1, dist2, ind1, ind2,dMax, ans;
		
		while(M--){
			visited.reset(); 
			cin >> x; x--;
			bool didIt = false;
			dMax = 0;
			if(colors[x] == BLACK){ colors[x] = WHITE; didIt = true; whites.insert(x);}
			for(set<int>::const_iterator it = whites.begin(); it != whites.end(); ++it){
				int j = *it;
				if(colors[j] == BLACK || visited.test(j)) continue;
				visited.set(j);
				dist = dist1 = dist2 = 0; ind1 = x; ind2 = j;
				if(H[ind1] > H[ind2]) swap(ind1,ind2);
				lca = E[query(H[ind1],H[ind2])];
				
				dist1 = L[H[ind1]]-L[H[lca]];
				dist2 = L[H[ind2]]-L[H[lca]];
				
				dist = dist1+dist2;
				
				if(dist >= dMax){
					dMax = dist;
					ans = j;
				}
			}
			if(!didIt){
				colors[x] = BLACK;
				whites.erase(x);
			}
			cout << ans+1 << '\n';
		}
	}	
}
Exemple #17
0
bool canmove(int a,int b)
{
	if (!st.test(b) && !m[a][b])
	{

	}

	return false;
}
Exemple #18
0
void sieve()
{
	int sq = ceil(sqrt(SIZE));
	for(int i = 2; i <= sq; ++i)
	{
		if(!prime.test(i))
		{
			for(int j = i*i; j <= SIZE; j += i)
				prime.set(j,1);
		}
	}

	for(int i = 2;i <= SIZE; ++i)
	{
		if(!prime.test(i))
			gpf.push_back(i);
	}
}
Exemple #19
0
// Dynamic programming recursion
int64_t dp(bitset<72> bs, int p) {

	// First check if this state is in memory
	map<bitset<72>, int64_t>::iterator it = mem.find(bs);
	if(it != mem.end()) return it->second;

	// Find the next set bit, going as far right and up
	// as possible until we get to the top-left corner
	while(!bs.test(p) && p > 0) {
		p < 24 ? p += 47 : p -= 24;
	}

	// Reached top-left corner, base case
	if(p == 0) return 1;

	int64_t res = 0;

	// Unset current bit (1x1 block placement)	
	bs.flip(p);
	res += dp(bs, p);
	
	// If bit above is in bounds and alive, place
	// place a 1x2 block instead of a 1x1
	if(p >= 24 && bs.test(p - 24)) {
		bs.flip(p - 24);
		res += dp(bs, p);
		bs.flip(p - 24);
	}

	// If bit to the left is in bounds and alive,
	// place a 2x1 block instead of a 1x1
	if(p % 24 != 0 && bs.test(p - 1)) {
		bs.flip(p - 1);
		res += dp(bs, p);
		bs.flip(p - 1);
	}

	// Reset to original bitboard and store result
	// in memory before returning
	bs.flip(p);
	mem[bs] = res;
	return res;
}
void dfs(int u, int v) {
	if (vis.test(u)) return;
	vis.set(u, true);
	f1[u] = v;
	f2[u] = c;
	c++;
	for (int p : edge[u]) {
		dfs(p, f2[u]);
	}
}
Exemple #21
0
void gen_sieve() {
	prime.reset();
	prime.flip();
	prime.set(0, false);
	prime.set(1, false);
	for (size_t i = 2; i <= primen; ++i)
		if (prime.test(i)) {
			for (size_t j = i * i; j <= primen; j += i)
				prime.set(j, false);
		}
}
Exemple #22
0
void sieve(void)
{
	int sq = (int)sqrt(SIZE);
	for(int i = 2; i <= sq; ++i)
	{
		if(!prime.test(i))
		{
			for(int j = (i*i); j <= SIZE; j += i)
			{
				prime.set(j,1);
			}
		}
	}

	for(int i = 2; i <= SIZE; ++i)
	{
		if(!prime.test(i))
			gpf.push_back(i);
	}
}
Exemple #23
0
void printArray()
{
	for (int i=0;i<MAX;i++)
	{
		if (mybs.test(i))
		{
			cout<<(i+1)<<" ";
		}
	}
	cout<<endl;
}
Exemple #24
0
int main()
{
    int cnt, count = 1;
    char name[55], n1[55], n2[55];
    while (scanf("%d", &V) != EOF)
    {
        cnt = 0;
        AdjList.assign(V, vi());
        inDegree.assign(V, 0);
        nameMap.clear();
        revNameMap.clear();
        for (int i = 0; i < 105; i++)
            visited.reset(i);
        for (int i = 0; i < V; i++)
        {
            scanf("%s", name);
            nameMap[string(name)] = cnt;
            revNameMap[cnt++] = string(name);
        }
        scanf("%d", &E);
        for (int i = 0; i < E; i++)
        {
            scanf("%s %s", n1, n2);
            if (!contains(nameMap[string(n1)], nameMap[string(n2)]))
            {
                AdjList[nameMap[string(n1)]].push_back(nameMap[string(n2)]);
                inDegree[nameMap[string(n2)]]++;
            }
        }
        printf("Case #%d: Dilbert should drink beverages in this order:",
               count++);
        bool done = false;
        while (!done)
        {
            done = true;
            for (int u = 0; u < V; u++)
            {
                if (inDegree[u] == 0 && !visited.test(u))
                {
                    done = false;
                    visited.set(u);
                    printf(" %s", revNameMap[u].data());
                    for (int i = 0; i < (int) AdjList[u].size(); i++)
                    {
                        inDegree[AdjList[u][i]]--;
                    }
                    u = -1;
                }
            }
        }
        printf(".\n\n");
    }
    return 0;
}
Exemple #25
0
bool isPrime(int p)
{
    if( p < SIEVE_SIZE )
       return bs.test(p);
    for(int i=0; i< primes.size()-1; i++)
    {
        if( p % primes[i] == 0 )
           return false;
    }
    return true;
}
Exemple #26
0
bool Check(int la, int cd)
{
    for (int j = N-1; j >= 1 ; --j)
    {
        int k = la+j*cd;
        
        if( !b.test(k) )
            return false;
    }
    return true;
}
void sieveGen() {
    pl.push_back(2);
    for(int  i = 3; i <= SZ; i +=2 ) {
        if( !sieve.test(i) ) {
            pl.push_back(i);
            for(int  k = i + i; k <= SZ; k += i )
                sieve.set(k);
        }
        //printf("%lld\n", i);
    }
}
void sieveGen(){
    sieve.flip();
    sieve.reset(0);
    sieve.reset(1);
    for( int k = 2; k <= OM; k++ )
        if(sieve.test(k)){
            pl.push_back(k);
            if(k <= sqrt(OM))
            for(int i = k + k; i <= OM; i += k )
                sieve.reset(i);
            }
}
Exemple #29
0
void generate_primes(ll upperbound)
{
	bs.reset();
	bs.flip();
	bs.set(0,false); bs.set(1,false);
	for(ll i = 2; i <= upperbound+1; i++) 
		if(bs.test((i))){
			for(ll  j = i * i ; j <= upperbound+1; j += i)
				bs.set(j,false);
		primes.push_back((int)i);
	}
	
}
Exemple #30
0
Fichier : i.cpp Projet : mrain/acm
void mksg(int i) {
	int l = (int)e[i].size();
	if (l == 0) return;
	vis.reset();
	for (int s = 1; s < two(l); ++ s) {
		if (bitcnt[s] > k[i]) continue;
		int t = 0;
		for (int j = 0; j < l; ++ j)
			if ((two(j) & s) != 0)
				t ^= sg[e[i][j]];
		vis.set(t);
	}
	while (vis.test(sg[i])) ++ sg[i];
}