Codeforces Round 1035 (Div. 2)

已经好久没有写CF了,毕竟之前是期末周,不得不准备期末考。然后昨晚一打比赛,无敌了,手感全无(还是要坚持CF啊)。

A题Problem - A - Codeforces

关注0 ^ 1 = 1, 1 ^ 1 = 0。

当a & 1 == 1 时候,a ^ 1 = a - 1,这是唯一一种让a变小的方法。如果是变大,0->1可以通过+1或者^1,而1->0只能+1。

#include <iostream>
#include <algorithm>

 
using namespace std;
typedef long long LL;
int main( )
{
    int t;
    cin >> t;
    while (t -- )
    {
        LL a, b, x, y;
        cin >> a >> b >> x >> y;
        LL ans = -1;
        if (b < a - 1) ans = -1;
        else if (b == a - 1)
        {
            if (a & 1 == 1) ans = y;
            else ans = -1;
        }
        else if (b == a) ans = 0;
        else
        {
            if (b % 2 == 0 && a % 2 == 0)
            {
                if (x <= y) ans = (b - a) * x;
                else ans = (b - a) / 2 * (x + y);
            }
            if (b % 2  == 1 && a % 2 == 1)
            {
                if (x <= y) ans = (b - a) * x;
                else ans = (b - a) / 2 * (x + y);
            }
            if (b % 2 == 0 && a % 2 == 1)
            {
                if (x <= y) ans = (b - a) * x;
                else ans = (b - a - 1) / 2 * (x + y) + x;
            }
            if (b % 2 == 1 && a % 2 == 0)
            {
                if (x <= y) ans = (b - a) * x;
                else ans = (b - a - 1) / 2 * (x + y) + y;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

B题Problem - B - Codeforces

经过n个a[i]后可以从(px,py)到达(qx,qy),则这n+1个线可以围成一个多边形(包括一条线),类似三角形我们知道,任意n个边的长度和>=剩下一个线长度就可以了。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
 
using namespace std;
typedef long long LL;
const int N = 2e6 + 10;
int main( )
{
    int t;
    cin >> t;
    while (t -- )
    {
        int n;
        cin >> n;
        LL px, py, qx, qy;
        cin >> px >> py >> qx >> qy;
        vector<long double> a(n + 1);
        LL x = px - qx, y = py - qy;
        LL dis = x * x + y * y;
        a[0] = sqrt(dis);
        
        double sum = a[0];
 
        for (int i = 1; i < n + 1; i ++ )
        {
            cin >> a[i];
            sum += a[i];
        }
        bool flag = true;
        for (int i = 0; i < n + 1; i ++ )
        {
            double check = sum - 2 * a[i];
            if (check < 0) flag = false;
        }
        if (flag) cout << "YEs" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C题Problem - C - Codeforces

这题考虑如何构造,为了最小,肯定是好多个l再配上别的。关注如何使得&和^相等。对于&,如果全是1,此时这一位是1。对于^,有奇数个1,就可以使得这一位是1。由此我们知道,如果n是奇数,那么全是l显然是最小的。下面考虑n是偶数。显然n=2肯定不可以,a & b = a ^ b,自行用1,0分别算算就知道了。n>=4时候,2个1000…0跟n - 2个l 就好了,这样结果都是0,找到1000…0在l~r之间就好了。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
 
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
 
LL a[N];
 
int main( )
{
    for (int i = 0; i <= 70; i ++ )
    {
        a[i] = 1LL << i;
    }
    int t;
    cin >> t;
    while (t -- )
    {
       LL n, l, r, k;
       cin >> n >> l >> r >> k;
       if (n % 2 == 1)
       {
            cout << l << endl;
            continue;
       }
       if (n == 2)
       {
            cout << -1 << endl;
            continue;
       }
       LL num = 0;
        for (int i = 0; i <= 70; i ++ )
        {
            if (a[i] > l && a[i] <= r)
            {
                num = a[i];
                break;
            }
        }
        if (num == 0) cout << -1 << endl;
        else
        {
            if (k <= n - 2) cout << l << endl;
            else cout << num << endl;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值