Ejemplo n.º 1
0
Archivo: 12911.cpp Proyecto: dibery/UVa
void all( vll& v, vll& l )
{
	for( int i = 0; i < v.size(); ++i )
	{
		vll tmp, comb;
		for( vlli j = l.begin(); j != l.end(); ++j )
			tmp.push_back( *j + v[ i ] );
		for( vlli m = l.begin(), n = tmp.begin(); m != l.end() || n != tmp.end(); )
			comb.push_back( n == tmp.end() || m != l.end() && *m <= *n? *m++ : *n++ );
		l.swap( comb );
	}
}
Ejemplo n.º 2
0
int main(){
	ios_base::sync_with_stdio(false);
	int T;
	ll a, b;
	cin >> T;
	preprocess();
	 while(T--){
		cin >> a >> b;
		if(a == b){
			cout << test(a) << '\n';
			continue;
		}
		vll::iterator first = lower_bound(nums.begin(), nums.end(),a), last = lower_bound(nums.begin(), nums.end(),b);
		cout << (int)(last - first) + (*last == b) << '\n';
		
	}
}
Ejemplo n.º 3
0
    static vll karatsubaMultiply(const vll &a, const vll &b) {
        int n = a.size();
        vll res(n + n);
        if (n <= 32) {
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    res[i + j] += a[i] * b[j];
            return std::move(res);
        }

        int k = n >> 1;
        vll a1(a.begin(), a.begin() + k);
        vll a2(a.begin() + k, a.end());
        vll b1(b.begin(), b.begin() + k);
        vll b2(b.begin() + k, b.end());

        vll a1b1 = karatsubaMultiply(a1, b1);
        vll a2b2 = karatsubaMultiply(a2, b2);

        for (int i = 0; i < k; i++)
            a2[i] += a1[i];
        for (int i = 0; i < k; i++)
            b2[i] += b1[i];

        vll r = karatsubaMultiply(a2, b2);
        for (int i = 0; i < (int)a1b1.size(); i++)
            r[i] -= a1b1[i];
        for (int i = 0; i < (int)a2b2.size(); i++)
            r[i] -= a2b2[i];

        for (int i = 0; i < (int)r.size(); i++)
            res[i + k] += r[i];
        for (int i = 0; i < (int)a1b1.size(); i++)
            res[i] += a1b1[i];
        for (int i = 0; i < (int)a2b2.size(); i++)
            res[i + n] += a2b2[i];
        return std::move(res);
    }
Ejemplo n.º 4
0
Archivo: 962.cpp Proyecto: rofi93/UVA
void gen(void)
{
    LL i,j,k;
    for(i=1;i<=1005;i++) arr[i]=i*i*i;
    for(i=1; i<=1005; i++)
    {
        for(j=i+1; j<=1005; j++)
        {
            k=arr[i]+arr[j];
            mp[k]++;
            if(mp[k]==2) cont.pb(k);
        }
    }
    sort(cont.begin(),cont.end());
    return;
}
Ejemplo n.º 5
0
int deal(){
    weight.clear();
    cin >> buf;
    int depth = 0;
    ll tmp;
    for (string::iterator ii = buf.begin(); ii != buf.end(); ii++){
        switch (*ii){
            case '[':
                {
                    depth++;
                }break;
            case ']':
                {
                    depth--;
                }break;
            case ',':break;
            default:
                {
                    tmp = 0;
                    while ('0' <= *ii && *ii <= '9') tmp = tmp * 10 + *ii - '0', ii++;
                    ii--;
                    weight.push_back(tmp << depth);
                }
        }
    }
    sort(weight.begin(), weight.end());
    int len = weight.size();
    int best = 0, cur = 1;
    weight.push_back(-1);
    for (int i = 0; i < len; i++){
        if (weight[i + 1] != weight[i]){
            best = max(best, cur);
            cur = 1;
        }
        else cur++;
    }
    return len - best;
}
Ejemplo n.º 6
0
bool in_lookup(const vll &l, long long n) // Lookup table method
{
    return std::find(l.begin(), l.end(), n) != l.end();
}