Codeforces Round #807 (Div. 2) A~D

A - Mark the Photographer

#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 205;
int g[N];
int t;
int n, x;
 
int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n >> x;
		for (int i = 1; i <= n + n; i++) cin >> g[i];
		sort(g + 1, g + n + n + 1);
		int flag = 0;
		for (int i = 1; i <= n; i++)
		{
			if (g[i + n] - g[i] < x)
			{
				flag = 1;
				break;
			}
		}
		if (flag == 1) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}

B - Mark the Dust Sweeper

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 200010;
LL g[N];
int t;
int n;

int main()
{
	cin >> t;
	while (t--)
	{
		LL res = 0;
		cin >> n;
		for (int i = 0; i < n; i++) cin >> g[i];

		int i = 0;
		while (g[i] == 0) i++;

		for (int j = i; j < n - 1; j++)
		{
			if (g[j] == 0) res++;
			else res += g[j];
		}

		cout << res << endl;
	}
	return 0;
}

C - Mark and His Unfinished Essay

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 45;
int t;
int n, c, q;
string s;
LL l[N], r[N], k;
LL len[N];

int main()
{
    cin >> t;
    while(t--)
    {
        cin >> n >> c >> q;
        cin >> s;
        len[0] = n;
        for(int i = 0; i < c; i++)
        {
            cin >> l[i] >> r[i];
            l[i]--;
            len[i + 1] = len[i] + r[i] - l[i];
            if(len[i + 1] > (LL) 1e18) len[i + 1] = (LL) 1e18;
        }
        while(q--)
        {
            cin >> k;
            k--;
            for(int i = c - 1; i >= 0; i--)
            {
                if(len[i] > k) continue;
                k = l[i] + (k - len[i]);
            }
            cout << s[k] << endl;
        }
    }
    return 0;
}

D - Mark and Lightbulbs

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int q, n;
string s, t;

int main()
{
    cin >> q;
    while(q--)
    {
        cin >> n >> s >> t;
        if(s[0] != t[0] || s[n - 1] != t[n - 1])
        {
            cout << -1 << endl;
            continue;
        }
        vector<int> a;
        for(int i = 0; i < n - 1; i++)
            if(s[i] != s[i + 1]) a.push_back(i);
            
        vector<int> b;
        for(int i = 0; i < n - 1; i++)
            if(t[i] != t[i + 1]) b.push_back(i);
        
        if(a.size() != b.size())
        {
            cout << -1 << endl;
            continue;
        }
        
        LL res = 0;
        for(int i = 0; i < a.size(); i++)
            res += abs(a[i] - b[i]);
        
        cout << res << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zyh_fighting

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值