SDNU_ACM_ICPC_2020_Winter_Practice_4th
2021-01-14 11:21
标签:-128 examples bing bad cout minimum exists 大于等于 from
InputThe first line contains only one integer T (T≤20T≤20), which indicates the number of test cases.
Sample Output You are given a string ss consisting of nn lowercase Latin letters. Let‘s define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 33 and ends in position 66 ), but "aa" or "d" aren‘t substrings of this string. So the substring of the string ss from position ll to position rr is s[l;r]=slsl+1…srs[l;r]=slsl+1…sr . You have to choose exactly one of the substrings of the given string and reverse it (i. e. make s[l;r]=srsr−1…sls[l;r]=srsr−1…sl ) to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string. If it is impossible to reverse some substring of the given string to obtain a string that is less, print "NO". Otherwise print "YES" and any suitable substring. String xx is lexicographically less than string yy , if either xx is a prefix of yy (and x≠yx≠y ), or there exists such ii (1≤i≤min(|x|,|y|)1≤i≤min(|x|,|y|) ), that xiyixiH - Triangle
any three of the remaining sticks.
For each test case, there is only one line describing the given integer n (1≤n≤201≤n≤20).OutputFor each test case, output one line “Case #x: y”, where x is the case number (starting from 1), y is the minimal number of sticks Wallice should steal.Sample Input3
4
5
6
Case #1: 1
Case #2: 1
Case #3: 2
思路:
用了斐波那契数列,因为数列中的任意三数都无法组成三角形,所以将1,2,3,,,n变成斐波那契数列就符合条件; 1 #include
K - Reverse a Substring
Input
The first line of the input contains one integer nn (2≤n≤3⋅1052≤n≤3⋅105 ) — the length of ss .
The second line of the input contains the string ss of length nn consisting only of lowercase Latin letters.
Output
If it is impossible to reverse some substring of the given string to obtain a string which is lexicographically less, print "NO". Otherwise print "YES" and two indices ll and rr (1≤lr≤n1≤l
Examples
7 abacaba
YES 2 5
6 aabcfg
NO
思路:先将字符串升序排序,与原字符串比较大小,若大于等于原字符串,则说明原字符串已经是字典序最小的排列方式;否则,逐一比较两字符串中元素,不同者,输出;
1 #include2 #include 3 #include string> 4 using namespace std; 5 int main() 6 { 7 int n; 8 char s[300005],m[300005]; 9 cin>>n; 10 for(int i=0;i ) 11 { 12 cin>>s[i]; 13 m[i]=s[i]; 14 } 15 sort(m,m+n); 16 for(int i=0;i ) 17 { 18 if(m[i]s[i]) 19 { 20 cout"YES"1" "; 21 for(int j=i+1;j ) 22 { 23 if(s[j]==m[i]) 24 { 25 cout1endl; 26 return 0; 27 } 28 } 29 } 30 } 31 cout"NO"; 32 33 34 35 }
L - Game with Telephone Numbers
SDNU_ACM_ICPC_2020_Winter_Practice_4th
标签:-128 examples bing bad cout minimum exists 大于等于 from
原文地址:https://www.cnblogs.com/wsytj/p/12257569.html
下一篇:关闭win10实时保护
文章标题:SDNU_ACM_ICPC_2020_Winter_Practice_4th
文章链接:http://soscw.com/index.php/essay/41754.html