Codeforces Round #805 (Div. 3) A-D

目录

题目:

A.Round Down the Price

题意:

思路:

code:

B. Polycarp Writes a String from Memory

题意:

思路:

code:

C. Train and Queries

题意:

思路:

code:

D. Not a Cheap String

题意:

思路:

code:

E. Split Into Two Sets

F. Equate Multisets

OS:


题目:

Dashboard - Codeforces Round #805 (Div. 3) - Codeforces

A.Round Down the Price

题意:

思路:

观察样例, 直接输出x - pow(10,x的位数-1)即可, (pow似乎是浮点数转换下int)

code:

/**
 *    author:  CurleyD
 *    created: 07.11.2022 04:51:31
**/
#include <bits/stdc++.h>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
typedef long long LL;
//#define LOCAL
//#define int LL
//head

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int T, n, m;

void solve() {
    string s;
    int t1, t2;
    cin >> t1;
    t2 = t1;
    while (t2) {
        s += t2 % 10;
        t2 /= 10;
    }
    cout << t1 - (int)pow(10, s.size()-1) << endl;
}

signed main() {
    IO;
    #ifdef LOCAL
        freopen("out.txt","w",stdout);
    #endif
    cin >> T;
    while(T--) {solve();}
    return 0;
}

B. Polycarp Writes a String from Memory

题意:

每次只能选3个不一样的, 问你最少几次能选完?

思路:

简单模拟, for一遍用个cnt或者和我一样用set都可以

code:

/**
 *    author:  CurleyD
 *    created: 07.11.2022 04:57:16
**/
#include <bits/stdc++.h>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
typedef long long LL;
//#define LOCAL
//#define int LL
//head

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int T, n, m;

void solve() {
    set<char> st;
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        st.insert(s[i]);
        if (st.size() > 3) {
            st.clear();
            cnt ++;
            st.insert(s[i]);
        }
    }
    cout << cnt + 1 << endl;
}

signed main() {
    IO;
    #ifdef LOCAL
        freopen("out.txt","w",stdout);
    #endif
    cin >> T;
    while(T--) {solve();}
    return 0;
}

C. Train and Queries

题意:

一列车从左到右单向经过n个站牌, 给你m组查询l, r 问能否从l开到r. 注意单向

思路:

我想的是如果l的最左边出现的位置还是比r的最右边出现的位置大的话那么证明一定不能从l开到r, 注意下给你查询的l,r可能没在经过那n个站牌里面, 不过出题人很良心啊, 样例就有这种情况owo!(对不仔细读题的我很友好hhh)

code:

/**
 *    author:  CurleyD
 *    created: 07.11.2022 05:03:10
**/
#include <bits/stdc++.h>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
typedef long long LL;
//#define LOCAL
//#define int LL
//head

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int T, n, m;

void solve() {
    map<int,int> posl;
    map<int,int> posr;
    map<int,int> pos;
    cin >> n >> m;
    vector<int> ve(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> ve[i];
        pos[ve[i]] = i;
        if (posl[ve[i]] != 0)
            posl[ve[i]] = min(posl[ve[i]], pos[ve[i]]);
        else
            posl[ve[i]] = pos[ve[i]];
        posr[ve[i]] = max(pos[ve[i]], pos[ve[i]]);
    }
    int l, r;
    while (m--) {
        cin >> l >> r;
        if (posl[l] > posr[r] || posl[l] == 0 || posr[r] == 0) 
            cout << "NO\n";
        else
            cout << "YES\n";
    }
}

signed main() {
    IO;
    #ifdef LOCAL
        freopen("out.txt","w",stdout);
    #endif
    cin >> T;
    while(T--) {solve();}
    return 0;
}

D. Not a Cheap String

题意:

给你个串s, 'a'的价值是1, 'b'是2.......等等, 给你目标价值m, 问你最少删除多少字母可以让总价值<=目标价值, 

思路:

贪心的想法, map标记这个字母出现的次数, 按照字典序从大到小sort下, 从大到小依次删, 看能删除后的情况: 1)删完这个正好达成目标, 那就标记(map[该字母] --) + break;  2)未达成目标, 那就继续删; 输出时候依次看map这个字母是否存在 1)存在 map--输出  2)不存在则不用管~

code:

/**
 *    author:  CurleyD
 *    created: 07.11.2022 05:13:34
**/
#include <bits/stdc++.h>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
typedef long long LL;
//#define LOCAL
//#define int LL
//head

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
int T, n, m;

void solve() {
    string s, t;
    map<char,int> mp;
    int sum = 0;
    cin >> s >> m;
    for (int i = 0; i < s.size(); i++) {
        sum += s[i] - 'a' + 1;
        mp[s[i]] ++;
    }
    t = s;
    sort(t.begin(), t.end(), greater<char>());
    for (int i = 0; i < t.size() && sum > m; i++) {
        if (sum - t[i] + 'a' - 1 <= m) {
            mp[t[i]] --;
            break;
        }
        else 
            sum = sum - t[i] + 'a' - 1, mp[t[i]] --;
    }
    for (int i = 0; i < s.size(); i++) {
        if (mp[s[i]] != 0) {
            cout << s[i];
            mp[s[i]] --;
        }
    }
    cout << endl;
}

signed main() {
    IO;
    #ifdef LOCAL
        freopen("out.txt","w",stdout);
    #endif
    cin >> T;
    while(T--) {solve();}
    return 0;
}

E. Split Into Two Sets

F. Equate Multisets

OS:

本来昨天想打的结果睡着了, 起来边吃早饭边VP了下, 还是只会做四个思维题, E他们说是二分图, F字典树? VP时间还没到, 看不了别人代码...但既然打了那就记录下吧, 直接贴我交的代码了, 之后会尽可能补上E,F的思路和代码.

有点后悔没打这场了, 起码我觉得30min出A-D没什么问题, 要是打的话估计能上个50多分, 距离摆脱灰名更进一步了就...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值