SDNU_ACM_ICPC_2020_Winter_Practice_4th

2021-01-14 11:21

阅读:685

标签:-128   examples   bing   bad   cout   minimum   exists   大于等于   from   

H - Triangle

Mr. Frog has n sticks, whose lengths are 1,2, 3??n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks! Output the minimal number of sticks he should steal so that Mr. Frog cannot form a triangle with
any three of the remaining sticks.

InputThe first line contains only one integer T (T20T≤20), which indicates the number of test cases.

For each test case, there is only one line describing the given integer n (1n201≤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  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;i6;i++)
13         {
14             if(n>=f[i])
15                 sum++;
16         }
17         cout"Case #"": ";
18         coutsum;
19         coutendl;
20     }
21     
22 }

K - Reverse a Substring

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+1srs[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]=srsr1sls[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 xyx≠y ), or there exists such ii (1imin(|x|,|y|)1≤i≤min(|x|,|y|) ), that xiyixijj (1ji1≤jxj=yjxj=yj . Here |a||a| denotes the length of the string aa . The lexicographic comparison of strings is implemented by operator

Input

The first line of the input contains one integer nn (2n31052≤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 (1lrn1≤l

Examples

Input
7
abacaba
Output
YES
2 5
Input
6
aabcfg
Output
NO

思路:先将字符串升序排序,与原字符串比较大小,若大于等于原字符串,则说明原字符串已经是字典序最小的排列方式;否则,逐一比较两字符串中元素,不同者,输出;
 1 #include  2 #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


评论


亲,登录后才可以留言!