hdu1177:"Accepted today?" 之基数排序



"Accepted today?"

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2351    Accepted Submission(s): 1052


Problem Description
Do you remember a sentence "Accepted today?" Yes, the sentence is mentioned frequently in lcy's course "ACM Programming"!
The contest is still in progress this moment. How excited it is! You, smart programmer, must have AC some problems today. "Can I get copper medal, silver medal, or even golden medal?" Oh, ha-ha! You must be considering this question. And now, the last problem of this contest comes.
Give you all submitting data in the contest, and tell you the number of golden medals, silver medals and copper medals; your task is to output someone's contest result.
Easy? Of course! I t is the reason that I designed the problem.
When you have completed this contest, please remember that sentence〃 Accepted today?〃儿
 

Input
Input contains multiple test cases. Each test case starts with five numbers N (4 =< N <= 130 -- the total number of attendees), G, S, C (1<=G<=S<=C<N --G, S, C denoting the number of golden medals, silver medals and copper medals respectively) and M (0<M<=N). The next N lines contain an integer P (1<=P<=8 --number of problems that have been solved by someone) and a time T(for example,"02:45:17", meaning 2 hours and 45 minutes and 17 seconds consumed according to contest rules) each. You can assume that all submit data are different.
A test case starting with 0 0 0 0 0 terminates input and this test case should not to be processed.
 

Output
For each case, print a sentence in a line, and it must be one of these sentences:
Accepted today? I've got a golden medal :)
Accepted today? I've got a silver medal :)
Accepted today? I've got a copper medal :)
Accepted today? I've got an honor mentioned :)

Note:
You will get an honor mentioned if you can't get copper medal, silver medal or golden medal.
 

Sample Input
10 1 2 3 6 2 02:45:17 2 02:49:01 2 03:17:58 2 03:21:29 4 07:55:48 3 04:25:42 3 06:57:39 2 02:05:02 2 02:16:45 2 02:41:37 0 0 0 0 0
 

Sample Output
Accepted today? I've got a silver medal :)
 

Author
lcy
 

Recommend
We have carefully selected several similar problems for you:  1084 1236 1263 1319 1174 
做这道题真心折磨!!
一看就知道是要用基数排序做,可是却没有思路。
好在看了别人的解题报告,自己再三咀嚼,于是才写出了AC代码!
还是那句话:AC不容易,且行且珍惜
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>

const int MAXN = 131;
int N,M;
int G, S, C;

struct node{
    int n,a, b, c;
}nd[MAXN];

void jspl(){
    int cnt[MAXN];
    int w[MAXN];
	int r[MAXN];
    int getc[MAXN];
    int num = 0;
    int i, j;
	
    while (num < 4){ //要排四层
        memset(cnt, 0, sizeof(cnt));
        if (num == 0){ //第一层
            for (i = 0; i < N; i++){
                w[i] = nd[i].c;
            }
        }
        else if (num == 1){//第二层
            for (i = 0; i < N; i++){
                w[i] = nd[getc[N-1-i]].b; //要从大到小放,这样才能从小到大放
				r[i]=getc[N-1-i]; //标记下排第N-1-i个是getc[N-1-i](原队列序号)
            }
        }
        else if (num == 2){//第三层
            for (i = 0; i < N; i++){
                w[i] = nd[getc[N-1-i]].a;
				r[i]=getc[N-1-i];
            }
        }
        else if (num == 3){//第四层
            for (i = 0; i < N; i++){
                w[i] = nd[getc[N-1-i]].n;
				r[i]=getc[N-1-i];
            }
        }
        for (i = 0; i < N; i++){
            cnt[w[i]]++;
        }
		if(num==2){
			for (i = 1; i < 25; i++){//注意
				cnt[i] += cnt[i - 1];//从小到大
			}
		}else if(num==3){
			for(i=6;i>=0;i--){
				cnt[i] += cnt[i + 1];//从大到小
			}
		}else{
			for (i = 1; i < 60; i++){
				cnt[i] += cnt[i - 1];//从小到大
			}
		}
		if(num==0){
			for (i = 0; i < N; i++){
				//printf("%d ",cnt[w[i]]);
				getc[--cnt[w[i]]] = i;//getc表示排在哪的是谁(序号标记)
			
			}
		}else{
			for (i = 0; i < N; i++){
				//printf("%d ",r[i]);
				getc[--cnt[w[i]]] =r[i];
			}
		}
		/*
		for(i=0;i<N;i++){
			printf("%d ",getc[i]);
		}
		printf("\n");
        */
		num++;
    }
	S=S+G;
	C=C+S;
	M--;
    for (i = 0; i < N; i++){
		if(getc[i]==M){
			if(1<=(i+1)&&(i+1)<=G){
				printf("Accepted today? I've got a golden medal :)\n");
			}else if((i+1)>G&&i+1<=S){
				printf("Accepted today? I've got a silver medal :)\n");
			}else if((i+1)>S&&i+1<=C){
				printf("Accepted today? I've got a copper medal :)\n");
			}else
				printf("Accepted today? I've got an honor mentioned :)\n");
			break;
		}
       // printf("%d ", getc[i]);
    }
}
int main(){
    int i, j;
    int n,a, b, c;
    freopen("in.txt", "r", stdin);
    while (~scanf("%d%d%d%d%d", &N, &G, &S, &C, &M) && N&&G&&S&&C&&M){
        char a1, a2;
        char b1, b2;
        char c1, c2;
        for (i = 0; i < N; i++){
            scanf("%d %c%c:%c%c:%c%c", &n, &a1,&a2, &b1,&b2, &c1,&c2);
            a = (a1 - '0') * 10 + a2 - '0';
            b = (b1 - '0') * 10 + b2 - '0';
            c = (c1 - '0') * 10 + c2 - '0';
            nd[i].n = n-1; //这里要n-1
            nd[i].a = a;
            nd[i].b = b;
            nd[i].c = c;
		//	printf("%d %d %d\n",a,b,c);
        }
        jspl();
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章