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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值