[HDU] [5499] SDOI

Problem Description

Loading...

Problem Analysis

This problem was actually never uploaded…
Okay~
Starting from this weekly practice, I began to feel the difficulty
I felt that my IQ is not enough -.-
It is time to enter the real learning-record period

The idea for this problem is to first calculate its actual score value

Then the output requirement is

If there is a female contestant, at least one female must be selected
If there is no female contestant, select the top m males

Note that
The output is always sorted by actual score in descending order

Then note that
When the value is 0
Some program implementations will go wrong

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<stdio.h>
#include<string.h>
#include <algorithm>
using namespace std;
struct ol {
	char name[25];
	char xing[10];
	double r1,r2,m;
};
bool vs(ol A,ol B) {
	return A.m>B.m;
}
int main() {
	int T;
	int i,j,n,m;
	double q,max;
	struct ol a[100];
	scanf("%d",&T);
	while(T--) {
		scanf("%d %d",&n,&m);
		for(i=0; i<n; i++)
			scanf("%s %s %lf %lf",&a[i].name,&a[i].xing,&a[i].r1,&a[i].r2);
		printf("The member list of Shandong team is as follows:\n");
		if(!m)
			continue;
		for(i=max=0; i<n; i++) {
			if(max<a[i].r1)
				max=a[i].r1;
		}
		q=300.0/max;
		for(i=0; i<n; i++) {
			a[i].r1*=q;
		}
		for(i=max=0; i<n; i++) {
			if(max<a[i].r2)
				max=a[i].r2;
		}
		q=300.0/max;
		for(i=0; i<n; i++) {
			a[i].r2*=q;
		}
		for(i=0; i<n; i++) {
			a[i].m=a[i].r1*0.3+a[i].r2*0.7;
		}
		sort(a,a+n,vs);
		for(i=0; i<m; i++) {
			if(!strcmp(a[i].xing,"female"))
				break;
		}
		if(i<m) {
			for(i=0; i<m; i++)
				printf("%s\n",a[i].name);
		} else {
			for(i=m; i<n; i++) {
				if(!strcmp(a[i].xing,"female")) {
					break;
				}
			}
			if(i<n) {
				for(j=0; j<m-1; j++)
					printf("%s\n",a[j].name);
				printf("%s\n",a[i].name);
			} else {
				for(i=0; i<m; i++)
					printf("%s\n",a[i].name);
			}
		}
	}
	return 0;
}

Problem address: HDU [5499] SDOI

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...