A.phone Numbers
Test instructions: give you n number, each number can only be used at most once, ask you can make up to 8 of the number of 11-digit phone numbers are the number of
Idea: Simulation can be, note that the char array read-in is starting from 0 subscript (here is hack ... )
1#include <bits/stdc++.h>2 intMain ()3 {4 intn,num=0, ans=0;5 Charc[ the];6scanf"%d%s",&n,c);7 for(intI=0; i<n;i++)if(c[i]=='8') num++;//The original is from 1 to n ...8 while(num>0&&n>= One)9 {Tennum--; Onen-= One; Aans++; - } -printf"%d\n", ans); the return 0; -}
View CodeB. Maximum Sum of Digits
Test instructions: Set a positive integer A, a and n, now given n, for each digit and the largest group (a, B), this and how much
Idea: Because it is to ask for each digit and, so specifically consider a specific number of segmentation, found that for a certain number of AI, regardless of how the points, whether borrow/be borrow, and are all AI, and the difference between the different methods is the reason whether borrow
This can be memory of DFS, set F (id,bor,now) to indicate to the ID bit, whether it is borrow (0,1), current digital and for now
Should pay attention to the borrow and not borrow the case of the decision (originally to consider less than borrow 9 can not borrow, was hack)
1#include <bits/stdc++.h>2 using namespacestd;3 intans=0, a[ the]={0};4 intmark[ the][5][255]={0};5 intDfsintIdintBorintNow )6 {7 if(id==a[0]+1)8 {9ans=Max (ans,now);Ten returnans; One } A - if(mark[id][bor][now]!=-1)returnMark[id][bor][now]; - the inttmp=0; - if(a[id]!=0) Tmp=max (Tmp,dfs (id+1,0, now+a[id]-Bor)); - //Μ±ç°î»²»îªáãôò¿¼âç²»ïòïâò»î»½èäçé¿ö£¨îª0ôò½èî»±ø軸üó壬çò°üº¬áë±»½èäçé¿ö£© - if(id!=a[0]&& (! ( a[id]==9&&bor==0)) Tmp=max (Tmp,dfs (id+1,1, now+a[id]+Ten-Bor)); + //¸ãî»öã²»îªxî¸ßî»çò²»îªã»±»½èýµä9£¬ôò¿¼âçïòïâò»î»½èî» - //ôà´éù¿¼âçáëã»óð½èýµä9²»äü½èî» + A returnmark[id][bor][now]=tmp; at } - intMain () - { - Long LongN; -scanf"%lld",&n); - while(n) in { -a[++a[0]]=n%Ten; toN/=Ten; + } -memset (mark,-1,sizeof(Mark)); theDfs1,0,0); *printf"%d\n", ans); $ return 0;Panax Notoginseng}
View CodeC. Maximum Subrectangle
Test instructions
D. Social Circles
Codeforces Round #513 by Barcelona bootcamp (rated, div. 1 + div. 2)