The main topic: There are n contestants to participate in the competition, the title of a total of three, and now give the N players each title score and the final ranking, (each question of the score based on the final check whether to give points, if not through 0 points, by getting the corresponding points), ask the last contestant can get the highest score is how much. (Same score, small ID row front)
The idea of disintegration: to the highest score, the first one must be three questions are right. Maintain a maximum score and the ID number of the previous person
Then judge the next score, if you have the same score, judge the ID number
If the current person's ID number is larger, you just need to update the ID.
If you do not have the same score or the same ID number is smaller than the previous one, find the value that is the highest score and less than the previous person's score.
If the above two conditions are not satisfied, there is no solution.
Note: The equal comparison of decimals can be converted to int first, and the last output divided by 100.0.
#include <cstdio>#include <algorithm>#include <cmath>#define MAXN 20000using namespace STD;structplayer{intscore[8];} P[MAXN];intn, ID[MAXN];intMain () {intCAS =1; while(scanf("%d", &n) = =1&& N) {Doubletmp_f[3];inttmp_i[3]; for(inti =1; I <= N; i++) {scanf("%LF%LF%LF", &tmp_f[0], &tmp_f[1], &tmp_f[2]); for(intj =0; J <3; J + +) Tmp_i[j] = (int) (Round (tmp_f[j] *100.0)); for(intj =0; J <8; J + +) {P[i].score[j] =0; for(intK =0; K <3; k++)if(J & (1<< k)) P[i].score[j] + + tmp_i[k]; } sort (P[i].score, P[i].score +8); } for(inti =1; I <= N; i++)scanf("%d", &id[i]);intMAX = p[id[1]].score[7];intpre_id = id[1], I; for(i =2; I <= N; i++) {intcur_id = Id[i];BOOLFlag =false; for(intj =7; J >=0; j--) {if(P[cur_id].score[j] = = MAX && cur_id > pre_id) {flag =true; pre_id = cur_id; Break; }if(P[cur_id].score[j] < MAX) {flag =true; pre_id = cur_id; MAX = P[cur_id].score[j]; Break; } }if(!flag) Break; }printf("Case%d:", cas++);if(I! = n +1)printf("No solution\n");Else printf("%.2lf\n", MAX/100.0); }return 0;}
UVA-1612 Guess Greed