Educational Codeforces Round 63 (Rated for Div. 2) A题

题目网址:https://codeforc.es/contest/1155/problem/A

题目大意:给定一串字符,可以选择其中的子串进行逆序变换,问进行变换后是否可以使新串的字典序小于原来的串,如果可以,输出变换的子串的头和尾位置。

题解:显然,只要找到一组满足题意的就行了,比如abcdefg,这样递增的就找不到,所以只要有递减的出现,比如acbdefg,就可以在第2,3个位置变换。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=3e5+7;
 4 char s[maxn];
 5 int main()
 6 {
 7     int n;
 8     cin>>n;
 9     scanf("%s",s+1);
10     for(int i=1;i<=n-1;i++) {
11         if(s[i]>s[i+1]) {
12             printf("YES\n");
13             printf("%d %d\n",i,i+1);
14             return 0;
15         }
16     }
17     printf("NO\n");
18     return 0;
19 } 
View Code

 

posted @ 2019-05-03 16:21  duxing201806  阅读(66)  评论(0编辑  收藏  举报