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;
}

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