Codeforces Round #581 (Div. 2) B. Mislove Has Lost an Array (贪心)

B. Mislove Has Lost an Array
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Mislove had an array a1, a2, ⋯, an of n positive integers, but he has lost it. He only remembers the following facts about it:

The number of different numbers in the array is not less than l and is not greater than r;
For each array's element ai either ai=1 or ai is even and there is a number ai2 in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 162=8.

According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.

Input
The only input line contains three integers n, l and r (1≤n≤1000, 1≤l≤r≤min(n,20)) — an array's size, the minimal number and the maximal number of distinct elements in an array.

Output
Output two numbers — the minimal and the maximal possible sums of all elements in an array.

Examples
inputCopy
4 2 2
outputCopy
5 7
inputCopy
5 1 5
outputCopy
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.

In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].

题意:

较简单,自行阅读。

思路:

最小的sum只需要完成元素种类个数是l,其他的用1去填。

最大的sum,先完成元素种类个数是r,其他的用(2^(r-1)) 填。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll l,r;
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n>>l>>r;
    ll ans1=0ll;
    ll base=1ll;
    repd(i,1,l)
    {
        ans1+=base;
        base*=2ll;
    }
    repd(i,l+1,n)
    {
        ans1++;
    }
    ll ans2=0ll;
    base=1ll;
    repd(i,1,r)
    {
        ans2+=base;
        base<<=1;
    }
    base>>=1;
    repd(i,r+1,n)
    {
        ans2+=base;
    }
    cout<<ans1<<" "<<ans2<<endl;
    
    
    
    return 0;
}
 
inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}
posted @ 2019-08-21 01:15  茄子Min  阅读(322)  评论(0编辑  收藏  举报