[Joj 2491]
[Original question link]
Http://acm.jlu.edu.cn/joj/showproblem.php? PID = 1, 2491
[Topic]
Enter the scores (Chinese and mathematics) of a group of students and classify the students. The grading method is to define the scores of one subject and one subject is higher than or equal to B, in this case, the level of A should be better than that of B. Each time, the level of A should be removed as the level, and the level of A should be downgraded, and so on. Enter the student ID and the output level.
You can also use DP, that is, based on the score DP:
If (score [I] [J]) level [I] [J] = (level [I + 1] [J]> level [I] [J + 1]? Level [I + 1] [J]: level [I] [J + 1]) + 1;
Else level [I] [J] = level [I + 1] [J]> level [I] [J + 1]? Level [I + 1] [J]: level [I] [J + 1];
This is the state transition equation. Other ideas are similar to the first method.
[Solution Thinking]
Use the score DP to classify students. It can also be classified from bottom to top.
[Code]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
Using namespace STD;
Long student [200005] [2], score [410] [410], level [410] [410];
Int main ()
{
Long casenum, stunum, I, j, L, M, testnum, stuid;
Scanf ("% lD", & casenum );
While (casenum --)
{
Scanf ("% lD", & stunum );
Memset (score, 0, sizeof (score ));
For (I = 0; I <stunum; I ++)
{
Scanf ("% LD % lD", & Student [I] [0], & Student [I] [1]);
Score [student [I] [0] [student [I] [1] ++;
}
L = 0;
While (stunum)
{
M =-1;
L ++;
For (I = 400; I> = 0; I --)
{
For (j = 400; j> m; j --)
{// Actually, use the score traversal function to find students with the same score.
If (score [I] [J])
{
M = J;
Stunum-= score [I] [J];
Level [I] [J] = L;
Score [I] [J] = 0;
Break;
}
}
}
}
Scanf ("% lD", & testnum );
While (testnum --)
{
Scanf ("% lD", & stuid );
Printf ("% LD \ n", level [student [stuid] [0] [student [stuid] [1]);
}
}
Return 0;
}
[\ Code]