首页 > 其他分享 >Codeforces Round 855 (Div. 3)--E

Codeforces Round 855 (Div. 3)--E

时间:2023-04-30 13:55:57浏览次数:44  
标签:855 cout -- s2 s1 t2 cin int Div

题意:

  给定一个k,可以任意次交换满足 | i - j | = k 或 | i - j |=k+1 的两个位置的元素

  很容易发现有区间内的字符是可以任意交换的,但是一个个字符考虑太混乱了(就是这样子把脑袋搞晕了),从左考虑那么(1,n - k)这个区间可以任意交换,从右考虑(k + 1, n)这个区间可以任意交换

  那么假如两个区间有交集,则整个字符串都可以任意交换两个元素的位置,否则就考虑中间空出来的那段是不是相同即可

链接:Problem - E2 - Codeforces

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

//不能随意变换的区间是(1,n-k)(k+1,n)

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        int n, k;
        string s1, s2;
        cin >> n >> k;
        cin >> s1 >> s2;
        s1 = " " + s1; s2 = " " + s2;
        int n1 = k + 1, n2 = n - k;
        string t1 = s1, t2 = s2;
        sort(t1.begin(), t1.end());
        sort(t2.begin(), t2.end());
        if (t1 != t2) {
            cout << "NO" << endl;
            continue;
        }
        if (n1 > n || n2 < 1) {
            if (s1 == s2)cout << "YES" << endl;
            else cout << "NO" << endl;
            continue;
        }
        if (n - k >= 1 + k) {
            cout << "YES" << endl;
        }
        else {
            string part3_s1 = s1.substr(n2 + 1, n1 - n2 - 1);
            string part3_s2 = s2.substr(n2 + 1, n1 - n2 - 1);
            if (part3_s2 == part3_s1)cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
    return 0;
}

 

标签:855,cout,--,s2,s1,t2,cin,int,Div
From: https://www.cnblogs.com/zhujio/p/17365200.html

相关文章

  • Codeforces Round 863 (Div. 3)———E
    题意:给定一个k,问由012356789组成的数字第k大的是多少链接:Problem-E-Codeforces#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;#defineendl"\n"/*思路:k代表在2没有出现4的数字中,第k大的数十进制表示由“0123456789”这九个数组......
  • 词向量在各个历史阶段的经典模型
    one-hot词表有多大,每个词的词向量就有多少维不足稀疏。没有语义信息。Word2Vec两种训练框架:CBOW:上下文预测中心词skip-gram:中心词预测上下文(wordembedding多用这种)word2vec的词向量考虑到了词的前后一定窗口内的上下文语义信息,且表示更加稠密。不足词向量是静态......
  • 博客园图片缩放调整
    上传图片后把![image](https://img2023.cnblogs.com/blog/2421910/202304/2421910-20230429223423752-834545576.png)改为<imgsrc="https://img2023.cnblogs.com/blog/2421910/202304/2421910-20230429223423752-834545576.png"style="zoom:50%"alt=&qu......
  • 笔记本自带的office哪去了?
    登录office官网点击右上角头像点击我的Microsoft账户点击上方导航栏的服务与订阅点击已购买的产品点击安装,选择版本中选择脱机安装程序下载后右键装载,双击出现的setUp.exe......
  • PTA题目集阶段总结(2)
    一、前言OOP训练集04:7题,第1题难度较大,第7题考查了较多的知识,也比较难;主要考察了Set、List和Java三大特性之一的封装性,并教我们学着查询JavaAPI文档,了解Scanner类、String类、Integer类、LocalDate类、ChronoUnit类中各种单位的用法和规则。OOP训练集05:6题,难度一般;主......
  • 09-react的组件传值 props
    //组件传值props接收传递过来的数据importReactDomfrom"react-dom"import{Component}from"react"//类组件中使用函数组件和类组件注意区分不同的组件使用不同方式接收数据constHellow=(props)=>{console.log(props)return<h1>函数组件</h1>}cla......
  • COMP30023远程调用程序
    COMP30023Project2RemoteProcedureCallOutdate:28April2023Duedate:Nolaterthan3pmFriday19May,2023AESTWeight:15%ofthefinalmark1ProjectOverviewRemoteProcedureCall(RPC)isacrucialtechnologyindistributedcomputingthatenablessof......
  • Deep Dynamics Models for Learning Dexterous Manipulation
    发表时间:2019(CoRL2019)文章要点:文章提出了一个onlineplanningwithdeepdynamicsmodels(PDDM)的算法来学习Dexterousmulti-fingeredhands,大概意思就是学习拟人的灵活的手指操控技巧。大概思路就是结合uncertainty-awareneuralnetworkmodels和gradient-freetrajecto......
  • Codeforces Round 855 (Div. 3)--D
    题意:给定一个字符串,删除其中连续两个字符,问有多少种不同字符串的情况#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;#defineendl"\n"//开始时假设每个点都对答案有贡献,考虑什么时候没有贡献//假如字符串某处出现aba这种//删除ab或者ba最后都是......
  • koa-compose 源码解析
    Koa-Compose函数解析1'usestrict'23/**4*Exposecompositor.5*/67module.exports=compose89/**10*Compose`middleware`returning11*afullyvalidmiddlewarecomprised12*ofallthosewhicharepassed.13*14......