1405 Mahershalalhashbaz, Nebuchadnezzar, and Billy Bob Benjamin Go to the regionals Constraints
Time limit:1 secs, Memory limit:32 MB
Description
the Association for Computing Machinery (ACM) are considering new rules for its regional programming C Ontests, in part to solve some software problems. For instance, the program this prints out of the badges for each team were designed so, the same font size are used to Prin T all badges to that team. However, this means if one member of the team have a very long name, then a very small font would be used to print all Of the team ' s badges, and this wouldn ' t look very nice for someone with a extremely short name like "AL".
the initial solution proposed by the ACM is to put a limit on the length of contestants ' names. Someone pointed out the this would discriminate against teams from certain regions where bigger names is more common (fo R instance, children in the home towns of well-known actors is more likely to being named after that actor–imagine how Mans Y children in Oakland, California has been named after the actor Mahershalalhashbaz Ali since he became one of the stars Of the television series The 4400).
as a compromise, the ACM decided to change the rule to require this" no team member ' s name can have the L Ength more than-away from the average length of the team member ' s names. Using This rule, a team consisting of "Mahershalalhashbaz", "AL", and "BILL" would being disqualified (average name length is 8, so AL and BILL is not within 2). However, "Mahershalalhashbaz", "Nebuchadnezzar", and "billybobbenjamin" would be okay (average name length is +, and all Team member names has length within 2 of this number). Given the names of n students, determine whether or not they can is placed into teams of K all Meets the requirements of the new ACM rule.
Input
Input would consist of multiple test cases. Each test case begins with a line consisting of positive integersNandk, whereN≤1000,k≤8, andNis divisible byk. Following this isNLines, each containing a single name consisting only the upper case letters with no embedded, leading, or trailing blanks. These is the names of theNStudents who need to being organized into teams of sizekeach. No name would exceed characters. The last test was followed by a line containing the zeros.
Output
For each test case, the output of the case number (starting at 1) followed by either the word "yes" (meaning that it is possible To organize the students into teams of size K so this no student on that team have a name whose length is greater than distance 2 from the average name lengths of the members on the this team), or "No" if it is not possible. Use the format shown in the sample output. Insert a blank line between cases.
Sample Input
3 3mahershalalhashbazalbill6 3mahershalalhashbazalnebuchadnezzarbillbillybobbenjaminjill0 0
Sample Output
Case 1:nocase 2:yes
A bit of water, according to the length of the string and then compare it ok:0s
#include <stdio.h> #include <algorithm> #include <string.h>using namespace std;struct name {char a[85] ;}; BOOL CMP (const name& AA, const name& BB) {return strlen (AA.A) < strlen (BB.A);} int main () {int control_case = 0, n, K; BOOL Is_ok, Control_blank = false; while (scanf ("%d%d", &n, &k) && n && k) {scanf ("\ n"); IS_OK = true; Name Nn[n]; for (int i = 0; i < n; i++) {gets (NN[I].A); } sort (nn, nn + n, CMP); /* for (int i = 0; i < n; i++) {printf ("%s\n", nn[i].a); } */int sum; for (int i = 0; i < n && is_ok; i + = k) {sum = 0; for (int j = i; J < i + K; j + +) {sum + = (int) strlen (NN[J].A); } for (int j = i, J < i + K; j + +) {if ((int) strlen (NN[J].A) > sum/k + 2) { IS_OK =False Break }}} if (Control_blank) printf ("\ n"); Control_blank = true; control_case++; printf ("Case%d:", control_case); if (IS_OK) printf ("yes\n"); else printf ("no\n"); } return 0;}
Sicily 1405. Mahershalalhashbaz, Nebuchadnezzar, and Billy Bob Benjamin Go to the regionals