首页 > 其他分享 >Educational Codeforces Round 160 (Rated for Div. 2) A~C

Educational Codeforces Round 160 (Rated for Div. 2) A~C

时间:2023-12-19 14:14:54浏览次数:43  
标签:Educational Rated const int Codeforces long typedef 字符串 include

A. Rating Increase

题意:

将一个字符串分成两个整数ab,要求没有前导0,且a < b

思路:

遍历字符串s,若当前位置不是0,则拆分字符串,比较大小

// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
// #include <queue>
// #include <map>
// #include <set>
using namespace std;

#define PIC 3.14159265358979
#define PI acos(-1)

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 1e6 + 10, M = 1e3 + 10;
const int mod1 = 1e9 + 7;
const int mod9 = 998244353;
const int INF = 1e9;

void solve() {
    string s; cin >> s;
    int n = s.size();

    for (int i = 1; i < n; i++) {
        if (s[i] != '0') {
            string a = s.substr(0, i);
            string b = s.substr(i, n - i);
            if (atoi(a.c_str()) < atoi(b.c_str())) {
                cout << a << ' ' << b << '\n';
                return;
            }
        }
    }
    cout << -1 << '\n';
    return;
}

int main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1; 
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

B. Swap and Delete

题意:

给定一个只包含01的字符串,可以进行以下操作:

  1. 删除一个字符串,消耗1金币
  2. 交换任意两个字符,不消耗金币

求将操作后的字符串与原字符串每一位都不相同的最少金币数

思路:

既然可以交换任意两个字符,且不消耗金币,那就说明可以任意排列字符串,那就先记录01的个数,在遍历一遍原字符串,原来字符串是0的位置放1,是1的位置放0,最后若是某一个数量不够,那么剩下的只能删除了

// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
// #include <queue>
// #include <map>
// #include <set>
using namespace std;

#define PIC 3.14159265358979
#define PI acos(-1)

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 1e6 + 10, M = 1e3 + 10;
const int mod1 = 1e9 + 7;
const int mod9 = 998244353;
const int INF = 1e9;

void solve() {
    string s; cin >> s;
    int n = s.size();

    int n0 = count(s.begin(), s.end(), '0');
    int n1 = count(s.begin(), s.end(), '1');

    for (int i = 0; i < n; i++) {
        bool tag = 0;
        if (s[i] == '0' && n1 > 0) {
            n1--;
            tag = 1;
        }
        if (s[i] == '1' && n0 > 0) {
            n0--;
            tag = 1;
        }

        if (!tag) {
            cout << n1 + n0 << '\n';
            return;
        }
    }
    cout << 0 << '\n';
    return;
}

int main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1; 
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

C. Game with Multiset

题意:

有m次操作,操作有两种

  1. ADD(x):在集合中添加\(2^x\)
  2. GET(x):查询集合中的元素能否相加组成x

空集为0

思路:

贪心,集合中从大到小遍历,若元素比x小则减去x中有该元素的个数和集合中有的个数的最小值乘以该元素,x -= min((x / (1 << i)), mp[i]) * (1 << i)

// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
// #include <queue>
#include <map>
// #include <set>
using namespace std;

#define PIC 3.14159265358979
#define PI acos(-1)

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 1e6 + 10, M = 1e3 + 10;
const int mod1 = 1e9 + 7;
const int mod9 = 998244353;
const int INF = 1e9;

void solve() {
    int t; cin >> t;
    map<LL, LL> mp;

    while (t--) {
        LL a, b; cin >> a >> b;
        if (a == 1) {
            mp[b]++;
        } else {
            if (b == 0) {
                cout << "YES" << '\n';
                continue;
            } else {
                for (int i = 30; i >= 0; i--) {
                    if (b >= (1 << i)) {
                        LL cnt = b / (1 << i);
                        b -= min(cnt, mp[i]) * (1 << i);
                    }
                }
                if (b  == 0) {
                    cout << "YES" << '\n';
                    continue;
                }
            }
            cout << "NO" << '\n';
        }
    }
}

int main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1; 
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

标签:Educational,Rated,const,int,Codeforces,long,typedef,字符串,include
From: https://www.cnblogs.com/-37-/p/17913582.html

相关文章

  • Educational Codeforces Round 160 (Rated for Div. 2)
    基本情况A题秒了。B题卡了实在太久,BC题最后虽然都过了,但是耗时太久。感觉C对我来说更好写。B.SwapandDelete经典+3。总是一条路偏要走到黑了才会想着换思路,早该换了。一开始想了一大堆乱七八糟的思路,但都错了。后面往简单了想,这题毕竟最后必须要左对齐的,直接从左往右比......
  • 【题解】CodeForces-1913
    CodeForces-1913ARatingIncrease依题意模拟。提交记录:Submission-CodeForcesCodeForces-1913BSwapandDelete交换免费就是能任意重排,从头开始尽量填相反的,剩下只能删去了。提交记录:Submission-CodeForcesCodeForces-1913CGamewithMultiset从大到小能减则减一定......
  • 【题解】CodeForces-1905
    CodeForces-1905AConstructiveProblems发现沿着对角线放就行了,答案是\(\max(n+m)\)。提交记录:Submission-CodeForcesCodeForces-1905BBegginer'sZelda最优操作每次删两个叶子(除了最后一次只剩两个节点),所以答案是叶子个数除以二上取整。提交记录:Submission-CodeForc......
  • k8s - error: 0/1 nodes are available: 1 node(s) had untolerated taint
     WarningFailedScheduling89sdefault-scheduler0/1nodesareavailable:1node(s)haduntoleratedtaint{node.cloudprovider.kubernetes.io││/uninitialized:true}.preemption:0/1nodesareavailable:1Preemptionisnothelpf......
  • class sun.reflect.GeneratedConstructorAccessor2 cannot access its superclass sun
    在启动JFinal程序时报错classsun.reflect.GeneratedConstructorAccessor2cannotaccessitssuperclasssun.reflect.Constructor问题所在因为这个项目的原作者是使用eclipse编写的,idea和eclipse的启动机制不一样,由于eclipse并没有自动实现热加载机制,因此这里我们需要加上......
  • Codeforces Round 834 (Div. 3)
    CodeforcesRound834(Div.3)A.Yes-Yes?题意:就是Y后面跟e,e后面跟s,s后面跟Y#include<iostream>usingnamespacestd;voidsolve(){stringx;cin>>x;intl=x.size();if(l==1){if(x[0]!='Y'&&x[0]!='e&#......
  • Codeforces Round 839 (Div. 3)
    CodeforcesRound839(Div.3)A.A+B?跳过太水了、、、、、#include<bits/stdc++.h>usingnamespacestd;intmain(){intt;cin>>t;while(t--){inta,b;scanf("%d+%d",&a,&b);cout<<a+......
  • Educational Codeforces Round 131 (Rated for Div. 2)
    基本情况AB秒了。C知道是二分答案,check死活写不出来。C.ScheduleManagementProblem-C-Codeforces错误分析这题比较绕,搞了一个对应关系,大脑转不过来。写check的时候完全想不出合理的思路。很明显的要用桶来计数,但是怎么用不知道了。看了题解后发现,check不能遍历任......
  • Educational Codeforces Round 159 (Rated for Div. 2)
    EducationalCodeforcesRound159(RatedforDiv.2)A-BinaryImbalance解题思路:有一对\((0,1)\),那么\(0\)就能无限增长。代码:#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=2e5+10;typedefpair<ll,ll>pii;constllm......
  • Codeforces Round 915 (Div. 2)
    基本情况A题还没进入状态,卡了快10分钟。B题一开始想复杂了,以为是树的直径,后面推出来发现针对叶子数目讨论就行了,正确思路出来太慢了(一个半小时)。C题留了半个多小时,随便口胡了一个LIS思路,但是判断无解没思路。C.LargestSubsequenceProblem-C-Codeforces首先我们把字......