2018SDIBT_国庆个人第三场
A - A
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 mm people 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 nn (1≤n≤100)(1≤n≤100) — the number of benches in the park.
The second line contains a single integer mm (1≤m≤10000)(1≤m≤10000) — the number of people additionally coming to the park.
Each of the next nn lines contains a single integer aiai (1≤ai≤100)(1≤ai≤100) — 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
4
6
1
1
1
1
3 7
1
10
5
15 15
3
6
1
6
5
6 12
3
7
1
6
5
7 13
Note
In the first example, each of four benches is occupied by a single person. The minimum kk is 33. 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 kk is 77. That requires all six new people to occupy the same bench.
The second example has its minimum kk equal to 1515 and maximum kk equal to 1515, as there is just a single bench in the park and all 1010 people will occupy it.
题意:公园里有n个长椅,现在有m个人要坐在长椅上,给出每个长椅上面原来坐了多少人,求来的这m个人坐上长椅后,长椅上的人数最小的最大值,和最大的最大值
分析:最小的最大值,m个人坐上长椅后,求出每个长椅上的人数的平均值,如果平均值小于了人数最大的长椅,那么最小的最大值就是最大长椅人数;如果平均值大于了最大长椅人数,那么最小的的最大值就是该平均值,当平均值为小数的时候,还要将平均数+1.
最大的最大值,m个人坐上长椅后,最大的最大值就等于m+最大长椅人数。
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 int main() 6 { 7 int n,m,a[105]; 8 while(~scanf("%d %d",&n,&m)) 9 { 10 int sum=0; 11 for(int i=1;i<=n;i++) 12 { 13 scanf("%d",&a[i]); 14 sum+=a[i]; 15 } 16 sort(a+1,a+1+n);//给原来长椅人数吧排序 17 int t,tt; 18 sum+=m;//所有人数之和 19 t=sum/n;//平均值 20 tt=sum%n; 21 if(t<a[n])//如果平均值小于最大长椅人数 22 { 23 printf("%d %d\n",a[n],a[n]+m); 24 } 25 else 26 { 27 if(tt!=0) 28 t++; 29 printf("%d %d\n",t,a[n]+m); 30 } 31 } 32 return 0; 33 }
B - B
Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
The first line contains a single integer nn (1≤n≤1000)(1≤n≤1000) — the number of juices.
Each of the next nn lines contains an integer cici (1≤ci≤100000)(1≤ci≤100000) and a string sisi — the price of the ii-th juice and the vitamins it contains. String sisi contains from 11 to 33 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string sisi. The order of letters in strings sisi is arbitrary.
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
4
5 C
6 B
16 BAC
4 A
15
2
10 AB
15 BA
-1
5
10 A
9 BC
11 CA
4 A
5 B
13
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
250
2
5 BA
11 CB
16
In the first example Petya buys the first, the second and the fourth juice. He spends 5+6+4=155+6+4=15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 1616, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
大致题意:有三种维生素,维生素A,B,C,每种橘子里至少包含一种维生素,这个人三种维生素都需要,且要求买橘子的花费最少,问你最少花费是多少
有n个橘子,下面n行,每行 c表示橘子的价钱和字符串s表示橘子所包含的维生素
代码很容易看懂,注意c++字符串格式
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 const int mmax = 0x3f3f3f; 6 std::string str; 7 int main() 8 { 9 using namespace std; 10 int n; 11 while(~scanf("%d",&n)) 12 { 13 int co,a=mmax,b=mmax,c=mmax,ab=mmax,ac=mmax,bc=mmax,abc=mmax,ans=mmax; 14 for(int i=1;i<=n;i++) 15 { 16 cin>>co>>str; 17 if(str=="A") 18 a=min(a,co); 19 else if(str=="B") 20 b=min(b,co); 21 else if(str=="C") 22 c=min(c,co); 23 else if(str=="AB"||str=="BA") 24 ab=min(ab,co); 25 else if(str=="AC"||str=="CA") 26 ac=min(ac,co); 27 else if(str=="BC"||str=="CB") 28 bc=min(bc,co); 29 else 30 abc=min(abc,co); 31 } 32 ans=min(ans,a+bc); 33 ans=min(ans,b+ac); 34 ans=min(ans,c+ab); 35 ans=min(ans,ab+bc); 36 ans=min(ans,ab+ac); 37 ans=min(ans,ac+bc); 38 ans=min(ans,abc); 39 ans=min(ans,a+b+c); 40 if(ans==mmax) 41 printf("-1\n"); 42 else 43 printf("%d\n",ans); 44 } 45 return 0; 46 }
D - D
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+1…sl+len−1(1≤l≤|s|,0≤len≤|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 (1≤T≤1001≤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 (5−2)+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
2
abcDCE
htQw27
abcD4E
htQw27
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).
大致题意:有T组样例,给你字符串s,把这个字符串改成符合要求的字符串,且改动长度最小,要求的字符串需要均包含大写字母,小写字母,数字。
分析:就分7种情况咯
只有小写字母 让第1,2个小写字母变为大写字母和数字
只有大写字母 让第1,2个大写字母变为小写字母和数字
只有数字 让第1,2个数字变为小写字母和大写字母
只有小写字母和大写字母 如果小写字母的数量>=2,就让其中的一个小写字母变为数字;如果大写字母的数量>=2,就让其中的一个大写字母变为数字。
只有小写字母和数字 如果小写字母的数量>=2,就让其中的一个小写字母变为大写字母;如果数字的数量>=2,就让其中的一个数字变为大写字母。
只有大写字母和数字 如果大写字母的数量>=2,就让其中的一个大写字母变为小写字母;如果数字的数量>=2,就让其中的一个数字变为小写字母。
小写字母大写字母数字都有 直接输出
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 int main() 6 { 7 int T; 8 char s[105]; 9 scanf("%d",&T); 10 while(T--) 11 { 12 int k,ans1=0,ans2=0,ans3=0; 13 scanf("%s",s); 14 k=strlen(s); 15 for(int i=0;i<k;i++) 16 { 17 if(s[i]>='a'&&s[i]<='z') 18 ans1++; 19 else if(s[i]>='A'&&s[i]<='Z') 20 ans2++; 21 else if(s[i]>='0'&&s[i]<='9') 22 ans3++; 23 } 24 if(ans1>0&&ans2>0&&ans3>0) 25 { 26 printf("%s\n",s); 27 } 28 else if(ans1>0&&ans2>0&&ans3==0) 29 { 30 if(ans1>=2) 31 { 32 for(int i=0;i<k;i++) 33 { 34 if(s[i]>='a'&&s[i]<='z') 35 { 36 s[i]='1'; 37 break; 38 } 39 } 40 printf("%s\n",s); 41 } 42 else if (ans2>=2) 43 { 44 for(int i=0;i<k;i++) 45 { 46 if(s[i]>='A'&&s[i]<='Z') 47 { 48 s[i]='1'; 49 break; 50 } 51 } 52 printf("%s\n",s); 53 } 54 55 } 56 else if(ans1>0&&ans3>0&&ans2==0) 57 { 58 if(ans1>=2) 59 { 60 for(int i=0;i<k;i++) 61 { 62 if(s[i]>='a'&&s[i]<='z') 63 { 64 s[i]='A'; 65 break; 66 } 67 } 68 printf("%s\n",s); 69 } 70 else if (ans3>=2) 71 { 72 for(int i=0;i<k;i++) 73 { 74 if(s[i]>='0'&&s[i]<='9') 75 { 76 s[i]='A'; 77 break; 78 } 79 } 80 printf("%s\n",s); 81 } 82 } 83 else if(ans2>0&&ans3>0&&ans1==0) 84 { 85 if(ans2>=2) 86 { 87 for(int i=0;i<k;i++) 88 { 89 if(s[i]>='A'&&s[i]<='Z') 90 { 91 s[i]='a'; 92 break; 93 } 94 } 95 printf("%s\n",s); 96 } 97 else if (ans3>=2) 98 { 99 for(int i=0;i<k;i++) 100 { 101 if(s[i]>='0'&&s[i]<='9') 102 { 103 s[i]='a'; 104 break; 105 } 106 } 107 printf("%s\n",s); 108 } 109 } 110 else if(ans1==0&&ans2==0&&ans3>0) 111 { 112 printf("aA"); 113 for(int i=2;i<k;i++) 114 printf("%c",s[i]); 115 printf("\n"); 116 } 117 else if(ans1==0&&ans3==0&&ans2>0) 118 { 119 printf("a1"); 120 for(int i=2;i<k;i++) 121 printf("%c",s[i]); 122 printf("\n"); 123 } 124 else if(ans2==0&&ans3==0&&ans1>0) 125 { 126 printf("A1"); 127 for(int i=2;i<k;i++) 128 printf("%c",s[i]); 129 printf("\n"); 130 } 131 } 132 return 0; 133 }
You are given a set of all integers from ll to rr inclusive, l<rl<r, (r−l+1)≤3⋅105(r−l+1)≤3⋅105 and (r−l)(r−l) is always odd.
You want to split these numbers into exactly r−l+12r−l+12 pairs in such a way that for each pair (i,j)(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 (1≤l<r≤10181≤l<r≤1018, r−l+1≤3⋅105r−l+1≤3⋅105, (r−l)(r−l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next r−l+12r−l+12 lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (r−l+1)(r−l+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
1 8
YES
2 7
4 1
3 8
6 5
题意:给你l,r,l-r一定是奇数,让你在l,r间找出(l-r+1)/2对数,一定有偶数对数,(i,j)满足最大公因数是1.
分析:每相邻的两个数的最大公因数就是1,所以遍历直接输出即可
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 int main() 6 { 7 long long n,m; 8 while(~scanf("%lld %lld",&n,&m)) 9 { 10 printf("YES\n"); 11 for(long long i=n;i<=m;i+=2) 12 { 13 printf("%lld %lld\n",i,i+1); 14 } 15 } 16 return 0; 17 }