2018SDIBT_国庆个人第五场
Posted 一只小毛球
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018SDIBT_国庆个人第五场相关的知识,希望对你有一定的参考价值。
A - ACodeForces 1060A
Description
Let‘s call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have $$$n$$$ cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don‘t have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer $$$n$$$ — the number of cards with digits that you have ($$$1 \leq n \leq 100$$$).
The second line contains a string of $$$n$$$ digits (characters "0", "1", ..., "9") $$$s_1, s_2, \ldots, s_n$$$. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Sample Input
11
00000000008
1
22
0011223344556677889988
2
11
31415926535
0
Hint
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can‘t make any phone number from the given cards.
题意:问你能组成多少个电话号码 像8xxxxxxxxxx的,给你n个卡片,每个卡片只能用一次或者不用
分析:不用考虑电话号码里具体的排列
1:如果给出的卡片没有8或者卡片数量小于11,直接输出0
2:t=卡片数除以11,如果t的数量大于号码为8的卡片的数量,则输出8的数量,否则输出t
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 int main() 8 { 9 int n,a[105]; 10 char s[105]; 11 while(~scanf("%d",&n)) 12 { 13 memset(a,0,sizeof(a)); 14 scanf("%s",s); 15 for(int i=0;i<n;i++) 16 { 17 a[s[i]-‘0‘]++; 18 } 19 if(a[8]==0||n<11) 20 printf("0\n"); 21 else 22 { 23 int t=n/11; 24 if(a[8]>t) 25 { 26 printf("%d\n",t); 27 } 28 else 29 printf("%d\n",a[8]); 30 } 31 } 32 return 0; 33 }
以上是关于2018SDIBT_国庆个人第五场的主要内容,如果未能解决你的问题,请参考以下文章