Codeforces Round #725 (Div. 3) 题解

Codeforces Round #725 (Div. 3)

A - Stone Game

传送门
思路:思维

#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int N = 500;
 
int a[N];
 
int main ()
{
    int t;
    cin >> t;
    while (t --)
    {
        int n, maxx = 0, minn = 0x3f3f3f3f, maxi, mini;
        cin >> n;
        for (int i = 1; i <= n; i ++)
        {
            cin >> a[i];
            if (a[i] <= minn)
            {
                minn = a[i];
                mini = i;
            }
            if (a[i] >= maxx)
            {
                maxx = a[i];
                maxi = i;
            }
        }
        int m1 = min (mini, maxi), m2 = max (mini, maxi);
        cout << min (n - m2 + 1 + m1, m2 - m1 + min (n - m2 + 1, m1)) << endl;
 
    }
}

B - Friends and Candies

传送门
思路:找到平均数,输出比平均数大的数的个数

#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int N = 2e5 + 10;
 
int a[N];
 
int main ()
{
    int t;
    cin >> t;
    while (t --)
    {
        int n;
        cin >> n;
        int sum = 0;
        for (int i = 1; i <= n; i ++)
        {
            cin >> a[i];
            sum += a[i];
        }
        if (sum % n != 0)
            cout << -1 << endl;
        else 
        {
            sum /= n;
            int ans = 0;
            for (int i = 1; i <= n; i ++)
            {
                if (a[i] > sum)
                    ans ++;
            }
            cout << ans << endl;
        }
 
    }
}

C - Number of Pairs

传送门
思路:二分找答案

#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int N = 2e5 + 100;
 
int a[N];
 
int main ()
{
    int t;
    cin >> t;
    while (t --)
    {
        long long n, L, R;
        cin >> n >> L >> R;
        for (int i = 0; i < n; i ++)
        {
            scanf ("%d", &a[i]);
        }
        sort (a, a + n);
        long long ans = 0;
        for (int i = 0; i < n; i ++)
        {
            long long cnt1, cnt2;
            
            cnt1 = lower_bound (a, a + n, L - a[i]) - a;
            if (cnt1 <= i + 1)
                cnt1 = i + 1;
            cnt2 = upper_bound (a, a + n, R - a[i]) - a;
            if (cnt2 <= i + 1)
                cnt2 = i + 1;
            ans += cnt2 - cnt1;
            if (cnt2 < n && a[cnt2] == R - a[i])
                ans ++;
        }   
        cout << ans << endl;
    }
}

D - Another Problem About Dividing Numbers

传送门
思路:累除

#include <iostream>
#include <algorithm>
#include <cmath>
 
using namespace std;
 
const int N = 2e5 + 100;
 
int division (int a, int res)
{
    if (a == 1)
        return res;
    for (int i = 2; i <= sqrt (a); i ++)
    {
        if (a % i == 0)
        {
            return division (a / i, res + 1);
        }
    }
    return res + 1;
}
 
int main ()
{
    int t;
    cin >> t;
    while (t --)
    {
        int a, b, k;
        scanf ("%d%d%d", &a, &b, &k);
        if (a < b)  swap (a, b);
        if (k == 1 && a == b)
        {
            printf ("NO\n");
            continue;
        }
        else if (k == 1 && a % b == 0)
        {
            printf ("YES\n");
            continue;
        }
        else if (k == 1 && a != b && a % b != 0)
        {
            printf ("NO\n");
            continue;
        }
        else if (a == 1 && b == 1 && k == 2)
        {
            printf ("NO\n");
            continue;
        }
        else 
        {
            int cnt = division (a, 0) + division (b, 0);
            if (cnt < k)
                printf ("NO\n");
            else 
                printf ("YES\n");
        }
    }
}

E - Funny Substrings

思路:模拟+字符串处理

G - Gift Set

传送门
思路:二分找答案最大值

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main ()
{
    int t;
    cin >> t;
    while (t --)
    {
        ll x, y, a, b;
        cin >> x >> y >> a >> b;
        if (a > b) swap (a, b);
        ll l = 0, r = 1e9, res = 0;
        while (l <= r)
        {
            ll mid = l + r >> 1;
            ll xx = x - mid * a;
            ll yy = y - mid * b;
            if (xx < 0 || yy < 0)
            {
                r = mid - 1;
                continue;
            }
            xx /= b;
            yy /= a;
            if (yy >= xx)
            {
               res = max (res, xx + mid);
               l = mid + 1;
            }
            else 
            {
                res = max (res, yy + mid);
                r = mid - 1;
            }
           
        }
        cout << res << endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值