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()); } }
void dfs(vector<vector<int>>& vv, bitset<maxNUM>& bt, int pos, int n, int k) { if(pos > n || bt.count() > k) return ; if(bt.count() == k && pos == n){ string ans = bt.to_string(); vector<int> vt; vt.clear(); for(int i = 0; i < n; i++) { if(ans[i] == '1') vt.push_back(i + 1); } vv.push_back(vt); return ; } bt.flip(maxNUM - pos - 1); dfs(vv, bt, pos + 1, n, k); bt.flip(maxNUM - pos - 1); dfs(vv, bt, pos + 1, n, k); }
void sieve() { p.flip(); p[0] = p[1] = 0; for(int i=2; i*i<MAX; i++) if( p[i] ) for(int j=i*i; j<MAX; j+=i) p[j] = 0; }
void sieve() { is_prime.flip(); for(int n = 3; n < SQRT_N; n += 2) if(is_prime[n>>1]) for(int j = n * n; j < MAX_N; j += (n<<1)) is_prime[j>>1] = false; is_prime[0] = false; }
void sieve(){ isp.reset(); isp.flip(); isp.set(0,false); isp.set(1,false); int i,j; rep(i,2,1000) if(isp[i]) repdf(j,2*i,1000000,i)isp.set(j,false); }
void populatePrime() // seive of eratosthenes { isPrime.reset(); isPrime.flip(); isPrime[0] = isPrime[1] = 0; for(int i=2; i*i<=MAX; i++) if(isPrime[i]) for(int j=i*i; j<MAX; j = j+i) isPrime[j] = 0; }
//Returns the result N after running PQ through all the gates bitset<30> Circuit::runGates(bitset<30> pq) { for(int i=0;i<gates.size();++i) { if(gates[i].noControllers()) { pq.flip(gates[i].getN()); flipped[i] = 1; } else { int flip = 1; vector<int> temp = gates[i].getControllers(); for(int j=0;j<temp.size();++j) { if(flip) { if(gates[i].getInverted()) { if(pq[temp[j]]) { flip = 0; } } else { if(!(pq[temp[j]])) { flip = 0; } } } } if(flip) { pq.flip(gates[i].getN()); flipped[i] = 1; } } } return pq; }
bitset<100> press ( int button, bitset<100> lamps, int N ) { if ( button == 1 ) return lamps.flip(); bitset<100> mask; int i= (button == 3) ? 1 : 0, leap = (button == 4) ? 3 : 2; for ( ; i < N; i+= leap) mask[100-i-1]= 1; return lamps^mask; }
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); } }
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); } }
inline void SieveOfAtkin(const int &largest) { int square; for (int i = 2; i < largest; ++i) primes[i] = false; primes.set(0, false); primes.set(1, false); primes.set(2, true); primes.set(3, true); //Sieve Of Atkin int n, nmod12; for (int x = 1; x <= 2236; ++x) { //x till root/2 for (int y = 1; y <= 4472; y += 2) { //odd y n = 4*x*x + y*y; nmod12 = n%12; if(n < largest && (nmod12 == 1 || nmod12 == 5)) primes.flip(n); } } for (int x = 1; x <= 4472; ++x) { for (int y = 1; y <= 4472; ++y) { n = 3*x*x + y*y; nmod12 = n%12; if(n < largest && (nmod12 == 7)) primes.flip(n); n = 3*x*x - y*y; nmod12 = n%12; if(x > y && n < largest && (nmod12 == 11)) primes.flip(n); } } //Eliminate by Sieve for (int i = 5; i <= 4472; ++i) { if(primes.test(i)) { square = i * i; for(int j = square; j <= largest; j += square) { primes[j] = false; } } } }
//Runs the gates in reverse on N in order to return the P and Q values bitset<30> Circuit::factorGates(bitset<30> n) { for(int i=gates.size()-1;i>=0;--i) { if(gates[i].noControllers()) { n.flip(gates[i].getN()); } else { int flip = 1; vector<int> temp = gates[i].getControllers(); for(int j=0;j<temp.size();++j) { if(flip) { if(gates[i].getInverted()) { if(n[temp[j]]) { flip = 0; } } else { if(!(n[temp[j]])) { flip = 0; } } } } if(flip) { n.flip(gates[i].getN()); } } } return n; }
void sieve(int upper_bound){ sieve_size = upper_bound; bs.reset(); bs.flip(); bs[0] = false; bs[1] = false; for(long long i = 2 ; i <= upper_bound ; i++) if(bs[i]){ for(long long j = i * i ; j <= upper_bound ; j += i) bs[j] = false; primes.push_back(i); } }
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; }
void create_prime() { prime.reset(); prime.flip(); prime[0]=prime[1]=0; for (long long i=2; i<MAX; ++i) { if (prime[i]) { for (long long j=i*i; j<MAX; j+=i){ prime[j]=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); } }
void build_sieve() { sieve = 0; sieve.flip(); sieve[0] = sieve[1] = 0; for ( aint n=2; n<MAXSIEVE; ++n ) { if ( !sieve[n] ) continue; for ( aint i=2*n; i<MAXSIEVE; i+=n ) sieve[i] = 0; } }
int main() { #ifdef _Rayn freopen("in.txt", "r", stdin); #endif int n, q; while(scanf("%d", &n) != EOF) { mp.clear(); for(int i = 0; i < n; i++) { scanf("%s %lld", buf, &byte[i]); l = buf; while((l = strchr(l, '[')) != NULL) { r = strchr(l, ']'); string tag = string(l+1, r); mp[tag].set(i, true); l = r; } } scanf("%d", &q); while (q--) { scanf("%s", buf); mask.reset(); mask.flip(); l = buf; while((l = strchr(l, '[')) != NULL) { r = strchr(l, ']'); string tag = string(l+1, r); if(!mp.count(tag)) { mask.reset(); break; } else { mask &= mp[tag]; } l = r; } long long res = 0; for (int i = 0; i < n; i++) { if (mask[i]) { res += byte[i]; } } printf("%lld\n", res); } } return 0; }
void mksieve(){ bs.reset(); bs.flip(); bs.set(0, false); bs.set(1, false); for(ll i = 2; i < sieveUpperBound; i++){ if(bs.test(i)){ for(ll j = i*i; j < sieveUpperBound; j += i){ bs.set(j, false); } primes.pb(i); } } }
// if bit is 1, then this bit is prime. void findPrime(bitset<MAX>& bs) { bs.reset(); bs.flip(); bs[0] = 0; bs[1] = 0; for (int i=2; i<=sqrt(MAX-1); i++) { if (bs[i] == 1) { for (int j=i*i; j<MAX; j+=i) { bs[j] = 0; } } } }
// if bit is 1, then this bit is prime. void findPrime(bitset<MAX2>& prime) { prime.reset(); prime.flip(); prime[0] = 0; prime[1] = 0; for (long long i=2; i<=sqrt(MAX2-1); i++) { if (prime[i] == 1) { for (long long j=i*i; j<MAX2; j+=i) { prime[j] = 0; } } } }
template<class V> void cmp_disorder_container(const V& container_a, const V& container_b, bitset<MAX_BITS_SIZE>& flag_a, bitset<MAX_BITS_SIZE>& flag_b) { int index = 0, count = 0; typename V::const_iterator iter = container_a.begin(); for (; iter != container_a.end(); iter++) { if ((index = find_key(*iter, container_b)) != -1 ) { count++; flag_a.set( distance(container_a.begin(), iter) ); flag_b.set(index); } } for (int i = container_a.size(); i < MAX_BITS_SIZE; i++) { flag_a.set(i); } for (int j = container_b.size(); j < MAX_BITS_SIZE; j++) { flag_b.set(j); } flag_a.flip(); flag_b.flip(); }
void sieve(ll upperBound,bitset<100007>&_bitset,vector<int>& primes){ ll sieveSize = upperBound + 1; _bitset.reset(); _bitset.flip(); //set all numbers to 1 _bitset.set(0,false); _bitset.set(1,false); for(ll i=2;i<=sieveSize;i++){ if(_bitset.test((size_t)i)){ for(ll j=i*i;j<=sieveSize;j+=i) _bitset.set((size_t)j,false); primes.push_back((int)i); } } }
// if bit is 1, then this bit is prime. void findPrime(bitset<MAX>& prime) { prime.reset(); prime.flip(); prime[0] = 0; prime[1] = 0; for (int i=2; i<=sqrt(MAX-1); i++) { if (prime[i] == 1) { for (int j=i*i; j<MAX; j+=i) { prime[j] = 0; } } } }
void sieve() { int i, j, max = SIEVE_SIZE + 1; bs.reset(); bs.flip(); bs.set(0, false); bs.set(1, true); for( i=2; i <= max; i++ ) { if( bs.test(i) == true ) // i é primo, e todos os múltiplos de i nao { primes.push_back( i ); for( j = i*i; j <= max; j += i ) { bs.set(j, false); } } } }
int main() { for(int i=0; i<26;i++) { scanf("%d", &wczytaj); bajtolomeusz.set(wczytaj,1); karty_bajt.insert(wczytaj); } przeciwnik = bajtolomeusz.flip(); for(int i=1;i<=52;i++) { if(przeciwnik[i]==0) continue; set<int>::iterator it = karty_bajt.lower_bound(i); if(it != karty_bajt.end()) { ile_wygranych++; karty_bajt.erase(it); }else { karty_bajt.erase(karty_bajt.begin()); } } printf("%d",ile_wygranych); return 0; }
bitset<28> AddOneBit(bitset<28> bitnum) //increases the bitset representation by one. Seems to run faster like this { bool ToSwitch; for(int i=K;i>=0;i--) { ToSwitch=true; int j=0; while(ToSwitch && j<i) { ToSwitch= (ToSwitch && bitnum.test(j)); j++; } if(ToSwitch) { bitnum.flip(i); } } return bitnum; }
static bool isPrime(int n) { static bool isInitialized = false; static bitset<MAX_INPUT> isPrime; if (!isInitialized) { isPrime.flip(); int i=2; while (i< MAX_INPUT) { for (int j = i+i; j< MAX_INPUT; j+= i) { isPrime[j] = false; } do { i++; } while (i < MAX_INPUT && !isPrime[i]); } isPrime[0] = false; isPrime[1] = false; isInitialized = true; } return isPrime[n]; }
void sieve(long long upperbound) ///create list of primes from 0 to upperbound { _sieve_size = upperbound + 1; bs.reset(); bs.flip(); /// set all numbers to 1 bs.set(0, false); bs.set(1, false); ///0 and 1 are not prime for(long long i = 2; i <= _sieve_size; i++) { if(bs.test((size_t)i)) { for(long long j = i*i; j <= _sieve_size; j += i) { bs.set((size_t)j, false); } primes.push_back((long long)i); } } }
void sieve() { is_prime.flip(); for(int n = 3; n < SQRT_N; n += 2) if(is_prime[n>>1]) for(int j = n * n; j < MAX_N; j += (n<<1)) is_prime[j>>1] = false; is_prime[0] = false; prime_gaps[num_primes] = 0; primes[num_primes++] = 2; for(int n = 3; n < MAX_N; n += 2) if(is_prime[n/2]) { primes[num_primes] = n; prime_gaps[num_primes] = primes[num_primes] - primes[num_primes-1]; //++num_primes; DEBUG(printf("primes[%d] = %d prime_gaps[%d] = %d\n", num_primes, primes[num_primes], num_primes, prime_gaps[num_primes])); ++num_primes; } }