Educational Codeforces Round 110 (Rated for Div. 2)部分题解

A

#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;
int a[10];
int main()
{
    int t;
    cin >> t;
    while (t --)
    {
        for (int i = 1; i <= 4; i ++ )
        {
            cin >> a[i];
        }
        int b = max(a[1], a[2]);
        int c = max(a[3], a[4]);
        sort(a + 1, a + 5);
        if ((a[3] == b && a[4] == c) || (a[3] == c && a[4] == b))
            cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

B

1≤i<j≤n  and gcd(ai,2aj)>1
#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;

int gcd(int a, int b)
{
    return b?gcd(b, a % b):a;
}
const int N = 2e3 +10;
int a[N], b[N],n;

int main()
{
    int t;
    cin >> t;
    while (t -- )
    {
        cin >> n;
        int j = 1;
        for (int i = 1; i <= n; i ++ ){
            cin >> a[i];
            if (a[i] % 2 == 0) b[j ++] = a[i];
        }
        int ans = 0;
        for (int i = 1; i <= n; i ++)
        {
            if (a[i] % 2) b[j ++] = a[i];
        }
        for (int i = 1; i <= n; i ++ )
        {
            for (int k = i + 1; k <= n; k ++ )
            {
                if (gcd(b[i], 2 * b[k]) > 1) ans ++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C

连续0101,1010串

#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

typedef long long ll;
const int N = 2e5 + 10;
int f[N][3];

int main()
{
    int t;
    cin >> t;
    while (t -- )
    {
        string a;
        cin >> a;
        memset(f, 0, sizeof f);
        for (int i = 0; i < a.size(); i ++ )
        {
            if (a[i] != '1') f[i][0] = f[i - 1][1] + 1;
            if (a[i] != '0') f[i][1] = f[i - 1][0] + 1;
        }
        ll ans = 0;
        for (int i = 0; i < a.size(); i ++ ) ans += max(f[i][0], f[i][1]);
        cout << ans << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值