Link: HDU 2409 team arrangement
Give 22 people (number, name, position of the kick, time in the team), let us select the DD-MM-SS of the Formation + a goalkeeper. In the selection of the Team Leader (the team leader who takes the longest time is the same time as the team leader), the selection order starts from the smaller number.
The structure sorting is fine. Note that the output is in the order of Captain, D, M, and S. Select the team leader to record the number of the Team Leader (instead of subscript, sort the code later ).
AC code:
# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; struct node {int num; char name [50]; char P [5]; int time; int OK ;}; struct node P [50]; int get_time (char s []) {int Len = strlen (s), I; int T1, T2, flag, sum; t1 = t2 = 0; flag = 0; sum = 0; for (I = 0; I <Len; I ++) {If (s [I] = '') {sum + = (t2-t1 + 1); flag = t1 = t2 = 0; continue;} If (s [I] = '-') {flag = 1; continue;} If (! Flag) T1 = T1 * 10 + s [I]-'0'; else t2 = T2 * 10 + s [I]-'0 ';} sum ++ = t2-t1 + 1; return sum;} bool CMP (node A, Node B) {return. num <B. num;} bool cmp2 (node A, Node B) {if (. OK! = B. OK) return. OK <B. OK; return. num <B. num;} int main () {int I; char s [500], HH [500]; int DD, mm, SS; int flag = 0; while (scanf ("% d", & P [0]. num )! = EOF, P [0]. num) {for (I = 0; I <22; I ++) P [I]. OK = 0; int temp; scanf ("% S % s", P [0]. name, P [0]. p); getchar (); gets (s); P [0]. time = get_time (s); for (I = 1; I <22; I ++) {scanf ("% d % S % s", & P [I]. num, P [I]. name, P [I]. p); getchar (); gets (s); P [I]. time = get_time (s); // printf ("% d .... \ n ", P [I]. time) ;}scanf ("% s", HH); dd = HH [0]-'0'; Mm = HH [2]-'0 '; ss = HH [4]-'0'; int mark = 0; sort (p, p + 22, CMP); for (I = 0; I <22; I ++) {If (P [I]. P [0] = 'G ') {P [I]. OK = 1; Mark = 1; break;} int COUNT = 0; for (I = 0; I <22; I ++) {If (P [I]. P [0] = 'D') {If (DD = 0) break; P [I]. OK = 2; dd -- ;}}for (I = 0; I <22; I ++) {If (P [I]. P [0] = 'M') {If (Mm = 0) break; P [I]. OK = 3; Mm -- ;}}for (I = 0; I <22; I ++) {If (P [I]. P [0] ='s ') {If (Ss = 0) break; P [I]. OK = 4; SS -- ;}} if (mark! = 1 | DD! = 0 | mm! = 0 | SS! = 0) // not selected full {printf ("impossible to arrange \ n"); continue;} int maxn =-1, max_ I; for (I = 0; I <22; I ++) {If (P [I]. OK) {If (P [I]. time> = maxn) {maxn = P [I]. time; max_ I = I; If (P [I]. time = maxn) {If (P [I]. num> P [max_ I]. num) max_ I = I ;}}} printf ("% d % S % s \ n", P [max_ I]. num, P [max_ I]. name, P [max_ I]. p); int Col = P [max_ I]. num; sort (p, p + 22, cmp2); for (I = 0; I <22; I ++) {If (P [I]. OK & Col! = P [I]. num) printf ("% d % S % s \ n", P [I]. num, P [I]. name, P [I]. p);} printf ("\ n");} return 0 ;}
HDU 2409 team arrangement (structured sorting)