https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=5085
The main idea: to give n individuals and each person's name s and the enemy he can kill number m, the number of these people can be killed by ranking and output, m query, each query output this person's two rankings,
One was that he was before his rank (he could not kill, note: He could not kill the number of people equal to his killing enemies) + 1, one was his rank before the number of enemies with whom he kills equals + 1
#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#include<algorithm>using namespacestd;Const intN = About;structst{intm, add, same, F; Chars[ -];} Node[n], a[n];intcmpConst void*a,Const void*b) {St*S1 = (ST *) A, *S2 = (ST *) b; if(S1->m! = s2->m)returnS2->m-s1->m; Else returnstrcmp (S1->s, s2->R); //Order by Dictionary}intMain () {intN, I, J, M; while(SCANF ("%d", &N), N) { for(i =0; I < n; i++) {scanf ("%s%d", Node[i].s, &node[i].m); Node[i].same= NODE[I].F =0; } qsort (node, n,sizeof(node[0]), CMP); scanf ("%d", &m); for(i =1; I <= m; i++) {scanf ("%s", A[I].S); for(j =0; J < N; J + +) { if(strcmp (A[I].S, node[j].s) = =0) A[i].add=J; } }//A[i].add is the first person's rank, ranking starting from No. 0 Place for(i =0; I < n-1; i++) { for(j = i +1; J < N; J + +) { if(NODE[I].M = =node[j].m) Node[j].same++; } }//Count The number of people he had killed before he ranked the enemy. for(i =0; I < n; i++) printf ("%s%d\n", Node[i].s, NODE[I].M); for(i =1; I <= m; i++) { if(Node[a[i].add].same >=1) printf ("%d%d\n", A[i].add-node[a[i].add].same +1, Node[a[i].add].same +1); Elseprintf ("%d\n", A[i].add-node[a[i].add].same +1); } } return 0;}
Uvalive 7077-song Jiang ' s rank list (analog)