Educational Codeforces Round 130 (Rated for Div. 2)(A-C)

A:

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

#define x first
#define y second
#define rep(i,a,n) for (int i = a; i < n; i ++ )
#define repn(i,a,n) for (int i = a; i <= n; i ++ )
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
typedef long long ll;
typedef pair<int,int> PII;

ll gcd(ll a,ll b) { return b ? gcd(b,a % b) : a; }
const int mod = 1e9+7;


int main()
{
    IOS;
    int t;
    cin >> t;
    while (t -- )
    {
        int n;
        cin >> n;
        int k;
        cin >> k;
        int res = 0;
        int sum = 0;
        for (int i = 0; i < n; i ++ )
        {
            int x;
            cin >> x;
            sum += x;
        }
        res = max(res, sum - k);
        cout << res << endl;
    }
    
    return 0;
}

B:

排序加前缀和

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

#define x first
#define y second
#define rep(i,a,n) for (int i = a; i < n; i ++ )
#define repn(i,a,n) for (int i = a; i <= n; i ++ )
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
typedef long long ll;
typedef pair<int,int> PII;

ll gcd(ll a,ll b) { return b ? gcd(b,a % b) : a; }
const int mod = 1e9+7;
const int N = 2e5;
ll a[N];
ll b[N];//前缀和

int main()
{
    IOS;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i ++ ) cin >> a[i];
    sort(a + 1, a + n + 1, greater<ll>());
    for (int i = 1; i <= n; i ++ )  b[i] = a[i] + b[i - 1];
    while(k -- )
    {
        ll x, y;
        cin >> x >> y;
        ll res = b[x] - b[x - y];
        cout << res << endl;
    }
    
    return 0;
}

C:我们可以这样想,因为两次操作都涉及到了B,所以我们可以假设B的位置是相对不变的,相对于答案是确定的。那么只需要去考虑a和c的位置,那么两个操作很明显可以看出来,ab->ba,a的位置肯定是往后移动了,当我们把答案中的a的位置记录下来的时候,原来的a肯定是在这个位置的前面或者正好在这个位置,(如果在前面,则需要进行交换,如果刚好,则不需要,如果在后面,则无法完成操作).所以只需要比较相对位置即可,同理,c也是如此!

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

#define x first
#define y second
#define rep(i,a,n) for (int i = a; i < n; i ++ )
#define repn(i,a,n) for (int i = a; i <= n; i ++ )
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
typedef long long ll;
typedef pair<int,int> PII;

ll gcd(ll a,ll b) { return b ? gcd(b,a % b) : a; }
const int mod = 1e9+7;

void solve()
{
        int n;
        cin >> n;
        string s, t;
        cin >> s >> t;

        for (auto c : {'a', 'b', 'c'}){
            if(count(s.begin(), s.end(),c) != count(t.begin(), t.end(),c)){
                cout << "NO"<< endl;
                return;
            }
        }
        string s1, t1;
        vector<int> x, y;
        for (int i = 0; i < n; i ++ )
        {
            if (s[i] != 'b'){
                s1 += s[i];
                x.pb(i);
            }
        }
        for (int i = 0; i < n; i ++ )
        {
            if (t[i] != 'b'){
                t1 += t[i];
                y.pb(i);
            }
        }
        if(s1 != t1){
            cout << "NO" << endl;
            return;
        }
        for (int i = 0; i < x.size(); i ++ )
        {
            if(s1[i] == 'a' ? (x[i] > y[i]) : (x[i] < y[i])){
                cout << "NO" << endl;
                return;
            }
        }
        cout << "YES" << endl;    
}

int main()
{
    IOS;
    int t;
    cin >> t;
    while (t -- )
    {
        solve();
    }
    
    return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值