zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 63 (Rated for Div. 2)

    Educational Codeforces Round 63 (Rated for Div. 2)

    A. Reverse a Substring

    • 题意

      第一行输入该字符串的长度,第二行输入该字符串。

      如果可以翻转该字符串的子串使得该字符串的字典序变小,则输出 “YES” 和 翻转的起始和终止位置,

      否则输出 “NO”,注意起始为 1,答案有多种,只用输出其中一种即可

    • 思路

      如果整个字符串的每个元素都递增,则输出“NO”,因为翻转后肯定会比原来的字典序大。

      找到第一个递减的字符,则需要翻转的位置为当前字符的位置和相邻的左边字符的位置。

      例如:

      7
      abacaba

      YES
      2 5

      找到第一个 ba 的位置,直接输出好了,也是其中一种答案。

      #include <bits/stdc++.h>
      using namespace std;
      int main(){
          ios::sync_with_stdio(0);
          cin.tie(0),cout.tie(0);
          //freopen("data.in","r",stdin);
          //freopen("data.out","w",stdout);
          int n,x,y;
          bool f = 0;
          string s;
          cin>>n>>s;
          for(int i = 0;i < s.length()-1; ++i){
              if(s[i] > s[i+1]){
                  f = 1;
                  x = i+1,y = i + 2;
                  break;
              }
          }
          if(!f) cout<<"NO
      ";
          else {
              cout<<"YES
      ";
              cout<<x<<" "<<y<<endl;
          }
          return 0;
      }
      

    B. Game with Telephone Numbers

    • 题意

      输入一个 n 为奇数且大于等于 13 的由纯数字组成的字符串。

      要求两名玩家轮流删除该字符串中的一个数字,A先手,B后手,在字符串长度变为 11 时停止游戏,

      如果该字符串变成以 8 为开头的序列,则 A 获胜,否则 A 失败。

    • 思路

      因为题目的获胜条件是得到以 8 开头的序列且长为 11 位,那么只用考虑,前(n-10)次操作

      能否留下至少一个 8 ,如果可以,就A获胜,否则就A失败。

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0),cout.tie(0);
        //freopen("data.in","r",stdin);
        //freopen("data.out","w",stdout);
        int n,cnt = 0;
        string s;
        cin>>n>>s;
        for(int i = 0;i < s.length() - 10; ++i){
            if(s[i] == '8') cnt++;
            else cnt--;
        }
        if(cnt > 0) cout<<"YES
    ";
        else cout<<"NO
    ";
        return 0;
    }
    
  • 相关阅读:
    zip
    sublime 3 注册码
    css3 文本控制自动换行
    ST3 package control
    cf1139D-Steps to One
    2019-2020 ACM-ICPC, Asia Xuzhou Regional Contest
    2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest
    Tree
    B
    多源对多源最短路
  • 原文地址:https://www.cnblogs.com/lukelmouse/p/10758409.html
Copyright © 2011-2022 走看看