A.codeforces1038A
You are given a string ss of length nn, which consists only of the first kk letters of the Latin alphabet. All letters in string ss are uppercase.
A subsequence of string ss is a string that can be derived from ss by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.
A subsequence of ss called good if the number of occurences of each of the first kkletters of the alphabet is the same.
Find the length of the longest good subsequence of ss.
Input
The first line of the input contains integers nn (1≤n≤1051≤n≤105) and kk (1≤k≤261≤k≤26).
The second line of the input contains the string ss of length nn. String ss only contains uppercase letters from 'A' to the kk-th letter of Latin alphabet.
Output
Print the only integer — the length of the longest good subsequence of string ss.
Examples
9 3
ACAABCCAB
6
9 4
ABCABCABC
0
Note
In the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.
In the second example, none of the subsequences can have 'D', hence the answer is 00.
题意:给你一个字符串s长度为n,让你求的字符串只包含k种字符且出现次数相等,你可以对字符串s进行删减操作,输出求得的字符串的长度
分析:只要找到字符串s里出现次数最少的字符,将它的出现次数乘以k,还要考虑当s里字符种数小于K的情况
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 int main() 6 { 7 int n,k,a[100],b[100]; 8 char s[100005]; 9 while(~scanf("%d %d",&n,&k)) 10 { 11 memset(a,0,sizeof(a));//a数组用来统计字符种数,如果出现了,就赋为1 12 memset(b,0,sizeof(b));//b数组用来统计每个字符出现的次数 13 scanf("%s",s); 14 int kk=0; 15 for(int i=0;i<n;i++) 16 { 17 if(a[s[i]-'A']==0) 18 { 19 kk++;//kk就表示s里字符的种数 20 a[s[i]-'A']=1; 21 } 22 b[s[i]-'A']++; 23 } 24 sort(b,b+k);//排序,找到出现次数最小的字符 25 if(kk!=k) 26 printf("0\n");//如果kk不等于给出的k时,输出0 27 else 28 printf("%d\n",b[0]*k);//最小的出现次数乘以字符种类数 29 30 } 31 return 0; 32 }
B.codeforces1038B
Find out if it is possible to partition the first nn positive integers into two non-empty disjoint sets S1S1 and S2S2 such that:
Here sum(S)sum(S) denotes the sum of all elements present in set SS and gcdgcd means thegreatest common divisor.
Every integer number from 11 to nn should be present in exactly one of S1S1 or S2S2.
Input
The only line of the input contains a single integer nn (1≤n≤450001≤n≤45000)
Output
If such partition doesn't exist, print "No" (quotes for clarity).
Otherwise, print "Yes" (quotes for clarity), followed by two lines, describing S1S1and S2S2 respectively.
Each set description starts with the set size, followed by the elements of the set in any order. Each set must be non-empty.
If there are multiple possible partitions — print any of them.
Examples
1
No
3
Yes
1 2
2 1 3
Note
In the first example, there is no way to partition a single number into two non-empty sets, hence the answer is "No".
In the second example, the sums of the sets are 22 and 44 respectively. The gcd(2,4)=2>1gcd(2,4)=2>1, hence that is one of the possible answers.
错了两发很是心痛,No,NO,Yes,YES其实很不一样
这题挺简单的,实际上就是构造。
题意:给你一个n,让你把1 to n的所有数分成两组,使得这两组的和的最大公因数不等于1,输出这两组数
分析:当n=1或者n=2时输出No,
当n大于2时,如果n为奇数,第一组数为中间那个数,第二组数为除开中间数的所有数,因为最中间数的旁边两个数之和一定是它的两倍,依次取左边一个右边一个,都满足,所以除开中间那个数的所有数之和一定是中间那个数的倍数。
如果n为偶数,第一组数取第一个数和最后一个数,第二组取剩下的数,因为第一个数与最后一个数之和等于第二个数与倒数第二个数之和,也等于第三个数和倒数第三个数之和....,所以剩下的数之和一定是第一个数和最后一个数之和的倍数。
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 int main() 6 { 7 int n; 8 while(~scanf("%d",&n)) 9 { 10 if(n==1||n==2) 11 printf("No\n");//当n=1或n=2 12 else 13 { 14 printf("Yes\n"); 15 if(n%2==0)//当n时偶数 16 { 17 printf("2 1 %d\n",n);//输出第一个数和最后一个数 18 printf("%d ",n-2);//剩下有n-2个数 19 for(int i=2;i<=n-1;i++) 20 { 21 if(i==n-1) 22 printf("%d\n",i); 23 else 24 printf("%d ",i); 25 } 26 } 27 else//当n是奇数 28 { 29 printf("1 %d\n",n/2+1); 30 printf("%d",n-1);//剩下有n-1个数 31 for(int i=1;i<=n;i++) 32 { 33 if(i!=n/2+1)//除开最中间的那个数不输出 34 printf(" %d",i); 35 } 36 printf("\n"); 37 } 38 } 39 } 40 return 0; 41 }
C.1038C Gambling