Exemple #1
0
int main() {
    scanf("%d", &n);

    scanf("%lld%lld", &l, &r);
    for (int i = 1; i <= n; i++) {
        scanf("%lld%lld", a + i, b + i);
        sorted[i] = i;
    }  // for

    sort(sorted + 1, sorted + n + 1, cmp);

    Integer pre;
    Integer answer;
    pre.number[0] = 1;
    pre *= l;

    for (int i = 1; i <= n; i++) {
        int p = sorted[i];
        Integer result = pre;
        result /= b[p];

        if (result > answer)
            answer = result;

        pre *= a[p];
    }  // for

    answer.print();

    return 0;
}  // function main
Exemple #2
0
void input()
{
	printf( "n> " );
	string line;
	getline( cin, line );

	size_t comma = line.find( "," );
	cout << endl;

	chrono::time_point<chrono::steady_clock> start;
	chrono::time_point<chrono::steady_clock> end;

	if (comma == string::npos )	// single mode
	{
		int n = atoi( line.c_str() );
		if ( n < 0 ) return;

		start = chrono::high_resolution_clock::now();
		Integer f = fibonacci( n );
		end = chrono::high_resolution_clock::now();

		f.print( Fibonacci::getNumberPrefix( n ) );
		f.toFile( FILENAME );
	}
	else	// range mode
	{
		i64 b = atoll( line.substr( 0, comma ).c_str() );
		i64 e = atoll( line.substr( comma+1, line.length() ).c_str() );

		start = chrono::high_resolution_clock::now();
		fibonacci_range( b, e );
		end = chrono::high_resolution_clock::now();
	}

	if ( benchmark )
	{
		chrono::duration<i64, nano> time = end - start;
		printf( "mode: %s | time: %lli ms", mode.c_str(), time.count()/ 1000000);
	}
	cout << endl;
	input();
}
Exemple #3
0
int main() {
    initialize();

    tpow[0].store(1);
    for (int i = 1; i <= m; i++) {
        tpow[i] = tpow[i - 1];
        tpow[i] *= 2;
    }  // for

    Integer answer;

    for (int p = 1; p <= n; p++) {
        for (int i = 1; i <= m; i++) {
            f[i][i] = tpow[m];
            f[i][i] *= mat[p][i];
        }  // for

        for (int l = 1; l < m; l++) {
            for (int i = 1; i <= m; i++) {
                int j = i + l;
                int selected = i - 1 + m - j + 1;
                Integer t1 = tpow[selected];
                Integer t2 = tpow[selected];
                t1 *= mat[p][i];
                t1 += f[i + 1][j];
                t2 *= mat[p][j];
                t2 += f[i][j - 1];

                if (t1 < t2)
                    f[i][j] = t2;
                else
                    f[i][j] = t1;
            }  // for
        }      // for

        answer += f[1][m];
    }  // for

    answer.print();

    return 0;
}  // function main