2021-5-11 CSUST 周练 Codeforces Gym #102894

Posted rivego

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021-5-11 CSUST 周练 Codeforces Gym #102894相关的知识,希望对你有一定的参考价值。

题目链接:https://codeforces.com/gym/102894



A - Big Brother Is Watching You

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7
const long long inf = 0x3f3f3f3f;
#define endl '\\ans'
int a[100005];
int main()
{
    int n, x, y;
    ll ansi = 0, ansm = 0;
    cin >> n >> x >> y;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] + x > y || (a[i] - x > y && a[i] - x >= 0))
        {
            ansm++;
        }
        if (a[i] + x > y && (a[i] - x > y && a[i] - x >= 0))
        {
            ansi++;
        }
    }
    cout << ansi << ' ' << ansm;
    return 0;
}

B - Santa Claus Is Coming To Town

模拟一下就行)
可以先算出不用通用礼物所需时间
先看x,y有没有比z大的,有的话就需要把差值减去
然后看是否还剩下通用礼物

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
#define endl '\\n'
int a[100005];
int main()
{
    ll n, m, x, y, z, k, flag = 0;
    cin >> n >> m >> x >> y >> z >> k;
    ll ans = n * x + m * y;
    int s = max(x - z, y - z);
    if (s > 0)
    {
        if (s == x - z)
        {
            ans -= min(n, k) * s;
            k -= min(n, k);
            flag = 1;
        }
        else
        {
            ans -= min(m, k) * s;
            k -= min(m, k);
            flag = 2;
        }
        if (k > 0)
        {
            if (flag == 1)
            {
                if (y > z)
                {
                    ans -= (y - z) * min(k, m);
                }
            }
            else if (flag == 2)
            {
                if (x > z)
                {
                    ans -= (x - z) * min(k, n);
                }
            }
        }
    }
    cout << ans;
    return 0;
}

C - Special Christmas Cake

画几个图就能看出一个多边形经过切割后最少多出两条边 最多四条边

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
#define endl '\\n'
int a[100005];
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if (a + b >= n + 2 && a + b <= n + 4)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
    return 0;
}

D - Important Documents

等差数列求和

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
#define endl '\\n'
int a[100005];
ll cal(ll n)
{
    return n * (1 + n) / 2;
}
int main()
{
    ll t, n, ans;
    cin >> t;
    while (t--)
    {
        cin >> n;
        ll l = 1, r = 1000000000;
        while (l <= r)
        {
            ll mid = (l + r) >> 1;
            if (n <= cal(mid))
            {
                r = mid - 1;
                ans = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        if (cal(ans) == n)
            ans++;
        cout << cal(ans) - n << endl;
    }

    return 0;
}

E - The Curious Case Of Vasya (待会补上)

F - Hotel Chevalier

贪心+二分

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
#define endl '\\n'
vector<int> room;
struct lei
{
    int p, m;
} num[200005];
bool cmp(lei a, lei b)
{
    return a.m > b.m;
}
int main()
{
    ll n, k, x;
    ll ans = 0;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &x);
        room.push_back(x);
    }
    for (int i = 1; i <= k; i++)
    {
        scanf("%d", &num[i].p);
    }
    for (int i = 1; i <= k; i++)
    {
        scanf("%d", &num[i].m);
    }
    int pos;
    sort(room.begin(), room.end());
    sort(num + 1, num + 1 + k, cmp);
    for (int i = 1; i <= k; i++)
    {
        pos = lower_bound(room.begin(), room.end(), num[i].p) - room.begin();
        if (room[pos] >= num[i].p && pos >= 0 && pos < room.size())
        {
            ans += num[i].m;
            room.erase(room.begin() + pos);
        }
    }
    cout << ans;
    return 0;
}

以上是关于2021-5-11 CSUST 周练 Codeforces Gym #102894的主要内容,如果未能解决你的问题,请参考以下文章

2021-5-11 CSUST 周练 Codeforces Gym #102894

周练1

cumt周练题解

周练4

周练7

周练5