寒假训练第八天-Codeforces Round #494 (Div. 3)

寒假训练第八天-Codeforces Round #494 (Div. 3)

前言:本来定的周日去补之前的题呢,然后给学弟们找寒假训练的内容忙了一天,然后家里又发生了一系列事情。今天的是补得昨天的题,仍然还是四道,等会有场div2,希望别掉分,时间不多了,还是只粘代码吧,明天会把这些天的题都补一下(补div3的,div2实力不够)。

题目链接-https://codeforces.com/contest/1003

A-Polycarp’s Pockets

int a[110], ok[110], ma;
int32_t main()
{
    ICO;
    int n = read();
    for(int i = 1; i <= n; i++)
    {
        a[i] = read();
        ok[a[i]]++;
        ma = max(ma, ok[a[i]]);
    }
    cout << ma;
    return 0;
}

B-Binary String Constructing

int32_t main()
{
    ICO;
    int a, b, x;
    cin >> a >> b >> x;
    string s1, s2, ss;
    if(a > b) ss = "01", s1 = "1", s2 = "0";
    else ss = "10", s1 = "0", s2 = "1";
    for(int i = 1; i <= x >> 1; i++) cout << ss;
    if(x & 1)
    {
        if(a <= b) swap(a, b);
        for(int i = 1; i <= a - (x >> 1); i++) cout << s2;
        for(int i = 1; i <= b - (x >> 1); i++) cout << s1;
    }
    else
    {
        if(a > b) swap(a, b);
        for(int i = 1; i <= a - (x >> 1); i++) cout << s1;
        for(int i = 1; i <= b - (x >> 1); i++) cout << s2;
    }
    return 0;
}

C-Intense Heat

const int maxn = 5e3 + 10;
int a[maxn], s[maxn];
int32_t main()
{
    ICO;
    int n, k;
    double res = 0;
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {cin >> a[i]; s[i] = s[i - 1] + a[i];}
    for(int i = 1; i <= n; i++)
        for(int j = i + k - 1; j <= n; j++)
            res = max(res, (s[j] - s[i - 1]) * 1.0 / (j - i + 1));
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

D- Coins and Queries

int a[32];
int32_t main()
{
    ICO;
    int n, q, x, res, t;
    cin >> n >> q;
    for(int i = 1; i <= n; i++) {cin >> x; a[(int)log2(x)]++;}
    while(q--)
    {
        res = 0;
        cin >> x;
        for(int i = 31; i >= 0; i--)
        {
            t = min(a[i], x >> i);
            res += t;
            if((x -= t * (1 << i)) <= 0) break;
        }
        if(x) cout << -1 << endl;
        else cout << res << endl;
    }
    return 0;
}

总结:事情可能会少一点,还是把训练恢复正轨,尽力吧 ,感觉上周还是在混日子。

上一篇:codeforces D. Palindrome Degree(hash)


下一篇:C语言:函数1.0