HDU1084(快速排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1084
应用系统自带的排序就可以轻松解决~~
代码如下:
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 using namespace std; 5 6 typedef struct 7 { 8 int solve; 9 int score; 10 int time; 11 int order; 12 } data; 13 14 data s[101]; 15 16 int cmp_1(const void *c, const void *d) 17 { 18 data *a = (data *)c; 19 data *b = (data *)d; 20 if(a->solve != b->solve) 21 { 22 return a->solve - b->solve; 23 } 24 if(a->solve == b->solve && a->time != b->time) 25 { 26 return a->time - b->time; 27 } 28 return 0; 29 } 30 31 int cmp_2(const void *c, const void *d) 32 { 33 data *a = (data *)c; 34 data *b = (data *)d; 35 return a->order - b->order; 36 } 37 38 int main() 39 { 40 int n; 41 int a, b, c; 42 int num[6]; 43 while(scanf("%d", &n) != EOF && n >= 0) 44 { 45 memset(num, 0, sizeof(num)); 46 for(int i = 0; i < n; i++) 47 { 48 scanf("%d %d:%d:%d", &s[i].solve, &a, &b, &c); 49 s[i].time = a * 3600 + b * 60 + c; 50 s[i].order = i; 51 num[s[i].solve]++; 52 if(s[i].solve == 0) 53 { 54 s[i].score = 50; 55 } 56 else 57 { 58 s[i].score = 50 + s[i].solve * 10; 59 } 60 } 61 qsort(s, n, sizeof(s[0]), cmp_1); 62 for(int i = 4; i >= 1; i--) 63 { 64 if(num[i] != 0) 65 { 66 int j; 67 int temp = num[i] / 2; 68 for(j = 0; j < n; j++) 69 { 70 if(s[j].solve == i) 71 { 72 break; 73 } 74 } 75 for(int k = 0; k < temp; k++) 76 { 77 s[j++].score += 5; 78 } 79 } 80 } 81 qsort(s, n, sizeof(data), cmp_2); 82 //printf("\n"); 83 for(int i = 0; i < n; i++) 84 { 85 printf("%d\n", s[i].score); 86 } 87 printf("\n"); 88 } 89 return 0; 90 }