首页 > 其他分享 >Codeforces Round 913 (Div

Codeforces Round 913 (Div

时间:2024-01-26 19:15:10浏览次数:40  
标签:std boy Lazy int Codeforces long Div 913 define

A Rook

题目大意

给一个国际象棋棋盘,有t次询问,每次询问给定一个棋子坐标s 例如 d4.

问: 输出这个棋子上下左右四个方向的坐标

解题思路

两个for循环暴力求解

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve(){
    std::string s;
    std::cin >> s;
    for(int i = 1; i <= 8 ; i ++)//枚举当前列
        if(i != s[1] - '0')
            std::cout << s[0] << i << endl;
  
    for(int i = 0; i < 8 ; i ++)//枚举当前行
        if(i + 'a' != s[0])
            std::cout << (char)(i + 'a') << s[1] << endl;
}

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

B YetnotherrokenKeoard

题目大意

t次询问,每次询问会给定一个字符串s,
我们要敲击键盘拼接出这个字符串,但是存在一些规则:

  1. 每次敲击b就会将位于这个b左边存在小写字母,那么就将距离b最近的一个删除,
  2. 同理,当敲击大写字母时,就会删除这个B左边最近的一个大写字母.

问: 最后会组成一个怎样的字符串.

解题思路

这个题由于数据量比较大,就不要尝试双重循环去删除字符了

我们可以发现一个规律,我们只删除当前字符前大小写形式相同的字符,并且只能删除一次,而且是删除距离最近的,

这就有点像堆栈(后进先出),那我们就可以用栈来模拟这个过程

我们可以给每个字符做个标记,即创建一个和字符串大小相同的bool数组

若为bB或被删除的字符标记为false,否则为true

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve() {
    std::string s;
    std::cin >> s;
    std::vector<bool> f((int) s.size(), true);
    std::stack<int> a, b;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] == 'b' || s[i] == 'B') {
            f[i] = false;
            if (isupper(s[i]) && !b.empty()){
                f[b.top()] = false;
                b.pop();
            }
            else if(islower(s[i]) && !a.empty()){
                f[a.top()] = false;
                a.pop();
            }
        } else {
            if(islower(s[i]))
                a.push(i);
            else
                b.push(i);
        }
    }
    while (!a.empty())
        a.pop();
    while (!b.empty())
        b.pop();
    for (int i = 0; i < (int) s.size(); i++)
        if (f[i])
            std::cout << s[i];
    std::cout << endl;
}

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

C Removal of Unattractive Pairs

题目描述

t次询问,每次询问给出一个长度为n的字符串,字符串两个字符不同则可以删除这两个字符

问: 字符串最短有多长.

解题思路

用手玩玩就ok

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve() {
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;
    std::vector<int> a(26, 0ll);
    for(auto i : s)
        a[i - 'a'] ++;
    int ma = *std::max_element(a.begin (), a.end());
    if(ma * 2 <= n)
        std::cout << n % 2 << endl;
    else 
        std::cout << n - 2 * (n - ma) << endl;
}

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

D Jumping Through Segments

题目描述

t次询问,每次询问会给nL, R,其中第 i 段从坐标为L[i]的点开始,到坐标为R[i]的点结束。
玩家从坐标为 0 的点开始通关。在一次移动中,他们可以移动到距离不超过 k 的任意一点。
在第i次移动后,玩家必须落在第i段之内,即在坐标x处,使得 L[i]≤x≤R[i]
这意味着,每次移动都必须在L[i] ~ R[i]

如果玩家按照上述规则到达了第 n个段落,那么这一关就算完成了。

为了不希望这个关卡太简单,所以要求确定可以完成这个关卡的最小整数k

解题思路

核心思想就是二分答案.

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve() {
    int n;
    std::cin >> n;
    std::vector<int> L(n, 0ll), R(n, 0ll);
    for(int i = 0 ; i < n ; i ++)
        std::cin >> L[i] >> R[i];
    int l = 0, r = 1e16 + 50;
    auto check = [&] (int x){
        int ma = 0, mi = 0;
        for(int i = 0 ; i < n ; i ++){
            ma = std::min (ma + x, INF);
            mi = std::max (mi - x, 0ll);
            mi = std::max(mi, L[i]);
            ma = std::min(ma, R[i]);
            if(mi > ma)
                return false;
        }
        return true;
    };
    while(l < r){
        int mid = (l + r) >> 1;
        if(check (mid)) r = mid;
        else l = mid + 1;
    }
    std::cout << r << endl;
}

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

标签:std,boy,Lazy,int,Codeforces,long,Div,913,define
From: https://www.cnblogs.com/Lazyboyjdj/p/17990491

相关文章

  • Codeforces Round 914 (Div
    AForked!题目大意给定王后和国王的位置,马可以先朝一个方向走a步,再朝另一个方向走b步问:马有多少个位置可以同时走到皇后和国王解题思路就无脑遍历一下马能走到国王和皇后的位置然后再判断下有没有相同的位置代码#include<bits/stdc++.h>#defineintlonglong......
  • Codeforces Round 916 (Div
    AProblemsolvingLog题目描述给一个整数n,字符串s,字符串中s[i]表示第i分钟解决第s[i]题.问题A需要1分钟解决,问题B需要2分钟解决,以此类推.问:可以解决多少题?解题思路遍历字符串,统计问题A--Z用了多少时间解决.最后在遍历数组,判断问题A--Z是否满足解决时间.代......
  • Educational Codeforces Round 159 (Rated for Div
    EducationalCodeforcesRound159(RatedforDiv.2)ABinaryImbalance题目大意给定一个长度为n的一个01字符串,我们执行以下操作:当s[i]!=s[i+1]在中间插入0问:是否可以实现0的个数大于1的个数解题思路由题意可以明显看出只要有0就可以实现。下面简单分析下:0的个数大......
  • Educational Codeforces Round 160 (Rated for Div
    ARatingIncreas题目大意给定一个数字,让我们拆分成两个数,这两个数满足以下条件:a<b.两个数没有前缀0.问:输出满足条件的数a,b.解题思路直接暴力循环这个数的位数次,若满足a<b,再判断两个数的位数和是否与拆分前相同.代码#include<bits/stdc++.h>#defin......
  • Educational Codeforces Round 161 (Rated for Div
    ATrickyTemplate题目描述给一个数字n和三个长度为n的字符串a,b,c。找一个模板使得字符串a,b匹配,而c不匹配,是否存在这样一个模板.匹配的定义是:当模板字母为小写时,两个字符串字符相同,为大写时,两个字符不同,这样的两个字符串则匹配解题思路我们可以直接得出当a字符串......
  • hey_left 17 Codeforces Round 817 (Div. 4)
    题目链接A.把标准字符串和输入字符串排序,看是否相等#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+10;voidsolve(){intn;cin>>n;stringt;cin>>t;strings="Timur";sort(s.begin(),s.end());......
  • hey_left 16 Codeforces Round 827 (Div. 4)
    题目链接A.判最大的数是不是另外两个数的和#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+10;voidsolve(){inta,b,c;cin>>a>>b>>c;cout<<(max({a,b,c})==a+b+c-max({a,b,c})?"YES":"......
  • Codeforces 1667E Centroid Probabilities
    这个连边方式就可以理解为\(1\)为根,点\(u\)的父亲\(fa_u\)满足\(fa_u<u\)。重心有不止一种表示法,考虑用“子树\(siz\ge\lceil\frac{n}{2}\rceil\)最深的点”来表示重心。令\(m=\lceil\frac{n}{2}\rceil\),\(f_i\)为节点\(i\)的\(siz\gem\)的方案数。考虑枚......
  • Codeforces Round 920 (Div. 3)
    赛时过了A~E,表现分1738。感觉D~G都挺有意义拿出来说的。[D]VeryDifferentArray首先一个贪心的猜想是:如果A和B长度相同,那一个顺序一个逆序应该是最优的情况。思考下如何证明这个猜想。假如A和B的长度均为2,易证\(A_1\)<\(A_2\),\(B_1\)>\(B_2\)时最优......
  • CodeForces 1667E Centroid Probabilities
    洛谷传送门CF传送门首先需要了解重心的三种定义:删掉一个点后剩下子树大小\(\le\frac{n}{2}\)的点\(\sum\limits_{i=1}^n\text{dis}(u,i)\)最小的点最深的\(sz_u\ge\left\lceil\frac{n}{2}\right\rceil\)的点这道题我们使用第三种定义,也就是要统计\(i\)为最......