标签:-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.
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 Input
3 4 5 6
Sample Output
Case #1: 1 Case #2: 1 Case #3: 2
思路:
用了斐波那契数列,因为数列中的任意三数都无法组成三角形,所以将1,2,3,,,n变成斐波那契数列就符合条件;
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int t,n,a,sum=0,f[6]={1,2,3,5,8,13}; 6 cin>>t;a=t; 7 8 while(t--) 9 { 10 cin>>n; 11 sum=0; 12 for(int i=0;i<6;i++) 13 { 14 if(n>=f[i]) 15 sum++; 16 } 17 cout<<"Case #"<<a-t<<": "; 18 cout<<n-sum; 19 cout<<endl; 20 } 21 22 }
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 xi<yixi<yi , and for any jj (1≤j<i1≤j<i ) xj=yjxj=yj . Here |a||a| denotes the length of the string aa . The lexicographic comparison of strings is implemented by operator < in modern programming languages??.
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≤l<r≤n1≤l<r≤n ) denoting the substring you have to reverse. If there are multiple answers, you can print any.
Examples
7 abacaba
YES 2 5
6 aabcfg
NO
思路:先将字符串升序排序,与原字符串比较大小,若大于等于原字符串,则说明原字符串已经是字典序最小的排列方式;否则,逐一比较两字符串中元素,不同者,输出;
1 #include <iostream> 2 #include <algorithm> 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<n;i++) 11 { 12 cin>>s[i]; 13 m[i]=s[i]; 14 } 15 sort(m,m+n); 16 for(int i=0;i<n;i++) 17 { 18 if(m[i]<s[i]) 19 { 20 cout<<"YES"<<endl<<i+1<<" "; 21 for(int j=i+1;j<n;j++) 22 { 23 if(s[j]==m[i]) 24 { 25 cout<<j+1<<endl; 26 return 0; 27 } 28 } 29 } 30 } 31 cout<<"NO"; 32 33 34 35 }
SDNU_ACM_ICPC_2020_Winter_Practice_4th
标签:-128 examples bing bad cout minimum exists 大于等于 from
原文地址:https://www.cnblogs.com/wsytj/p/12257569.html