Codeforces Round #524 (Div. 2)A B C

A. Petya and Origami

题解:签到。

#include<bits/stdc++.h>
typedef long long LL;
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
	int n,k;
	cin>>n>>k;
	int one[3] = {2,5,8};
	for(int i = 0; i < 3; ++i) {
		one[i] = ceil(n * one[i] * 1.0 / k);
	}
	LL sum = 0;
	for(int i = 0; i < 3; ++i)
		sum += one[i];
	cout << sum << endl;
    return 0;
}

B. Margarite and the best present

题解:会等差数列的人应该都会做…我的做法就是将其分为公差为 2 2 2 − 2 -2 2的两组数列,然后求和。

#include<bits/stdc++.h>
typedef long long LL;
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
	int q,l,r; 
	cin>>q;
	while(q--) {
		scanf("%d%d",&l,&r);
		LL sum = 0;
		if(l & 1) {
			if(r & 1) { 
				// 1 4 // 1 3
				int n = (r - l + 1) / 2 + 1;
				sum -= n * 1LL * l + 1LL *n * (n - 1);
				n--;
				sum += n * 1LL * (l + 1) + 1LL * n * (n - 1);
			}else{
				int n = (r - l + 1) / 2;
				sum -= n * 1LL * l + 1LL * n * (n - 1); // 2 * 1 + 2 
				sum += n * 1LL * (l + 1) + 1LL * n * (n - 1);//2 * 2 + 2 
			}
		}else{
			if(r & 1) { 
				int n = (r - l + 1) / 2; // 2 * 2 + 2
				sum += n * 1LL * l + 1LL *n * (n - 1);
				sum -= n * 1LL * (l + 1) + 1LL * n * (n - 1);
			}else{
				int n = (r - l + 1) / 2 + 1;
				sum += n * 1LL * l + 1LL * n * (n - 1);
				n--;
				sum -= n * 1LL * (l + 1) + 1LL * n * (n - 1);
			}
		}
		printf("%lld\n",sum);
	}
    return 0;
}

C. Masha and two friends

题解:先染一次白色,再染一次黑色,如果有重叠就删去多加的白的。除了判断位置麻烦些其它都是小事。

#include<bits/stdc++.h>
typedef long long LL;
using namespace std;

struct rec{
    int x1,y1,x2,y2;
    rec() {}
    rec(int a,int b,int c,int d) { x1 = a; y1 = b; x2 = c; y2 = d;}
};
int n,m;
bool comb(rec t)
{
    if(t.x1 <= t.x2 && t.y1 <= t.y2)
        return 1;
    return 0;
}

LL all(rec a)
{
    LL n = a.y2 - a.y1 + 1;
    LL m = a.x2 - a.x1 + 1;
    return n * m;
}

LL color_w(rec a)
{
    LL a_m = a.x2 - a.x1 + 1, a_n = a.y2 - a.y1 + 1;
    if((a.x1 + a.y1) % 2 == 0) {
        return ((a_m * a_n + 1)/ 2);
    }
    return  (a_m * a_n / 2);
}

LL color_b(rec a)
{
    return all(a) - color_w(a);
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    int T;
    cin >> T;
    while (T--) {
        rec a, b;
        cin >> n >> m;
        cin >> a.x1 >> a.y1 >> a.x2 >> a.y2;
        cin >> b.x1 >> b.y1 >> b.x2 >> b.y2;
        LL sum_w = (1LL * n * m + 1) / 2;
        sum_w += color_b(a);
        sum_w -= color_w(b);
        //重叠部分
        rec t = rec{max(a.x1, b.x1), max(a.y1, b.y1), min(a.x2, b.x2), min(a.y2, b.y2)};
        if (comb(t) == 1) {
            sum_w -= color_b(t);
        }
        cout << sum_w << ' ' << 1LL * n * m - sum_w << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值