国庆练习3

牧云@^-^@ 提交于 2020-01-26 04:00:05

Benches CF 1042A

There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of nn available.

Let kk be the maximum number of people sitting on one bench after additional mmpeople came to the park. Calculate the minimum possible kk and the maximum possible kk.

Nobody leaves the taken seat during the whole process.

Input

The first line contains a single integer n(1n100) — the number of benches in the park.

The second line contains a single integer m (1m10000) — the number of people additionally coming to the park.

Each of the next nn lines contains a single integer ai (1ai100) — the initial number of people on the ii-th bench.

Output

Print the minimum possible kk and the maximum possible kk, where kk is the maximum number of people sitting on one bench after additional mm people came to the park.

Examples

Input
461111
Output
3 7
Input
1105
Output
15 15
Input
36165
Output
6 12
Input
37165
Output
7 13

Note

In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench.

The second example has its minimum k equal to 15 and maximum kk equal to 15, as there is just a single bench in the park and all 10 people will occupy it.

 

题目意思:

有n个长椅,依次给出每张椅子上最初有的人数,现在增加m个人,这m个人可以随意选择座位,k代表是所有长椅中最大的人数,最后求k的最大值与最小值。

解题思路:

k(max) = 所有的m个人坐在起初人最多的地方。

k(min) = 既保证坐的人数量最大,又要求此时的k最小,那么只能是平均分。但平均分完人数之后,很有可能均分的人数是要比你起初最大的人数要小,所以需要比较一下。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define ll long long int
 5 using namespace std;
 6 int a[110];
 7 int main()
 8 {
 9     int n,m,i,j,sum,maxs,x,y;
10     scanf("%d%d",&n,&m);
11     sum=0;
12     maxs=0;
13     for(i=0;i<n;i++)
14     {
15         scanf("%d",&a[i]);
16         sum+=a[i];
17         if(a[i]>maxs)
18         {
19             maxs=a[i];
20         }
21     }
22     y=maxs+m;
23     sum+=m;
24     if(sum%n)
25     {
26         x=sum/n+1;
27     }
28     else
29     {
30         x=sum/n;
31     }
32     x=max(x,maxs);
33     printf("%d %d\n",x,y);
34     return 0;
35 }

 

Relatively Prime Pairs CF 1051B

You are given a set of all integers from ll to rr inclusive, l<rl<r, (rl+1)3105and (rl) is always odd.

You want to split these numbers into exactly rl+12 pairs in such a way that for each pair (i,j) the greatest common divisor of ii and jj is equal to 11. Each number should appear in exactly one of the pairs.

Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.

Input

The only line contains two integers ll and rr (1l<r1018rl+13105(rl) is odd).

Output

If any solution exists, print "YES" in the first line. Each of the next rl+12lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (rl+1) numbers should be pairwise distinct and should have values from ll to rr inclusive.

If there are multiple solutions, print any of them.

If there exists no solution, print "NO".

Example

Input
1 8
Output
YES2 74 13 86 5题目意思:给定两个数l,r,已知l-r是奇数,那么l,r一个为奇数,一个为偶数.求[l,r]区间两两成对的数,需要满足GCD(a,b)=1;共有(l-r+1)/2对。如果满足题意的话,输出YES,并且把每一对按要求输出。解题思路:算是一个性质吧,相邻两个数的GCD必为1。一奇一偶。注意数据范围,开long long。
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define ll long long int
 5 using namespace std;
 6 int main()
 7 {
 8     ll l,r,i;
 9     scanf("%lld%lld",&l,&r);
10     printf("YES\n");
11     for(i=l;i<=r;i+=2)
12     {
13         printf("%lld %lld\n",i,i+1);
14     }
15     return 0;
16 }

 


Vasya And Password CF 1051A

Vasya came up with a password to register for EatForces — a string ss. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.

But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least one uppercase Latin letter and at least one lowercase Latin letter. For example, the passwords "abaCABA12", "Z7q" and "3R24m" are valid, and the passwords "qwerty", "qwerty12345" and "Password" are not.

A substring of string ss is a string x=slsl+1sl+len1(1l|s|,0len|s|l+1)x=slsl+1…sl+len−1(1≤l≤|s|,0≤len≤|s|−l+1). lenlen is the length of the substring. Note that the empty string is also considered a substring of ss, it has the length 00.

Vasya's password, however, may come too weak for the security settings of EatForces. He likes his password, so he wants to replace some its substring with another string of the same length in order to satisfy the above conditions. This operation should be performed exactly once, and the chosen string should have the minimal possible length.

Note that the length of ss should not change after the replacement of the substring, and the string itself should contain only lowercase and uppercase Latin letters and digits.

Input

The first line contains a single integer TT (1T1001≤T≤100) — the number of testcases.

Each of the next TT lines contains the initial password s (3|s|100)s (3≤|s|≤100), consisting of lowercase and uppercase Latin letters and digits.

Only T=1T=1 is allowed for hacks.

Output

For each testcase print a renewed password, which corresponds to given conditions.

The length of the replaced substring is calculated as following: write down all the changed positions. If there are none, then the length is 00. Otherwise the length is the difference between the first and the last changed position plus one. For example, the length of the changed substring between the passwords "abcdef" →"a7cdEf" is 44, because the changed positions are 22 and 55, thus (52)+1=4(5−2)+1=4.

It is guaranteed that such a password always exists.

If there are several suitable passwords — output any of them.

Example

Input
2abcDCEhtQw27
Output
abcD4EhtQw27

Note

In the first example Vasya's password lacks a digit, he replaces substring "C" with "4" and gets password "abcD4E". That means, he changed the substring of length 1.

In the second example Vasya's password is ok from the beginning, and nothing has to be changed. That is the same as replacing the empty substring with another empty substring (length 0).

题目意思:给出一个密码,该密码可能不满足要求,请改为符合要求的密码,新密码必须含有大写字母、小写字母和数字。

解题思路:这个题很恶心啊,分很多种情况,不好幸亏很多代码是重复的。。。。。

 

1.小写字母大写字母数字都有 直接输出

2.只有小写字母 让第1,2个小写字母变为大写字母和数字

3.只有大写字母 让第1,2个大写字母变为小写字母和数字

4.只有数字 让第1,2个数字变为小写字母和大写字母

5.只有小写字母和大写字母 如果小写字母的数量>=2,就让其中的一个小写字母变为数字;如果大写字母的数量>=2,就让其中的一个大写字母变为数字。

6.只有小写字母和数字 如果小写字母的数量>=2,就让其中的一个小写字母变为大写字母;如果数字的数量>=2,就让其中的一个数字变为大写字母。

7.只有大写字母和数字 如果大写字母的数量>=2,就让其中的一个大写字母变为小写字母;如果数字的数量>=2,就让其中的一个数字变为小写字母。

 

  1 #include<cstdio>
  2 #include<cstring>
  3 #include<algorithm>
  4 using namespace std;
  5 char s[110];
  6 int main()
  7 {
  8     int n,i,len;
  9     int a,b,c;
 10     scanf("%d",&n);
 11     getchar();
 12     while(n--)
 13     {
 14         memset(0,sizeof(s),0);
 15         scanf("%s",s);
 16         len=strlen(s);
 17         a=0,b=0,c=0;
 18         for(i=0; i<len; i++)
 19         {
 20             if(s[i]>='A'&&s[i]<='Z')
 21             {
 22                 a++;
 23             }
 24             else if(s[i]>='a'&&s[i]<='z')
 25             {
 26                 b++;
 27             }
 28             else if(s[i]>='0'&&s[i]<='9')
 29             {
 30                 c++;
 31             }
 32         }
 33         if(a>0&&b>0&&c>0)///三者都有
 34         {
 35             puts(s);
 36         }
 37         else if(a>0&&b==0&&c==0)///只有大写
 38         {
 39             s[0]='a';
 40             s[1]='1';
 41             puts(s);
 42         }
 43         else if(b>0&&a==0&&c==0)///只有小写
 44         {
 45             s[0]='A';
 46             s[1]='1';
 47              puts(s);
 48         }
 49         else if(c>0&&a==0&&b==0)///只有数字
 50         {
 51             s[0]='A';
 52             s[1]='a';
 53             puts(s);
 54         }
 55         else if(a==0&&b>0&&c>0)///没有大写,只有小写和数字
 56         {
 57             if(b>=2)
 58             {
 59                 for(i=0; i<len; i++)
 60                 {
 61                     if(s[i]>='a'&&s[i]<='z')
 62                     {
 63                         s[i]='A';
 64                         break;
 65                     }
 66                 }
 67                 puts(s);
 68                 c=0;
 69             }
 70             else if(c>=2)
 71             {
 72                 for(i=0; i<len; i++)
 73                 {
 74                     if(s[i]>='0'&&s[i]<='9')
 75                     {
 76                         s[i]='A';
 77                         break;
 78                     }
 79                 }
 80                 puts(s);
 81             }
 82         }
 83         else if(b==0&&a>0&&c>0)///没有小写,只有大写和数字
 84         {
 85             if(a>=2)
 86             {
 87                 for(i=0; i<len; i++)
 88                 {
 89                     if(s[i]>='A'&&s[i]<='Z')
 90                     {
 91                         s[i]='a';
 92                         break;
 93                     }
 94                 }
 95                 puts(s);
 96                 c=0;
 97             }
 98             else if(c>=2)
 99             {
100                 for(i=0; i<len; i++)
101                 {
102                     if(s[i]>='0'&&s[i]<='9')
103                     {
104                         s[i]='a';
105                         break;
106                     }
107                 }
108                 puts(s);
109             }
110         }
111         else if(c==0&&a>0&&b>0)///没有数字,只有大写和小写
112         {
113             if(a>=2)
114             {
115                 for(i=0; i<len; i++)
116                 {
117                     if(s[i]>='A'&&s[i]<='Z')
118                     {
119                         s[i]='1';
120                         break;
121                     }
122                 }
123                 puts(s);
124                 b=0;
125             }
126             else if(b>=2)
127             {
128                 for(i=0; i<len; i++)
129                 {
130                     if(s[i]>='a'&&s[i]<='z')
131                     {
132                         s[i]='1';
133                         break;
134                     }
135                 }
136                 puts(s);
137             }
138         }
139     }
140     return 0;
141 }

 

 

 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!