首页 > ACM题库 > HDU-杭电 > HDU 1177 “Accepted today?” 模拟[解题报告] C++
2013
12-03

HDU 1177 “Accepted today?” 模拟[解题报告] C++

“Accepted today?”

问题描述 :

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 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.

输出:

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.

样例输入:

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

样例输出:

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

竟然和上次竞赛的一个题目差不多,可以上次没做出来

Problem : 1177 ( "Accepted today?" )     Judge Status : Accepted
RunId : 5592110    Language : C++    Author : ssun
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

struct PP{
    int count;
    string time;
};

bool cmp(PP p1, PP p2)
{
    if(p1.count>p2.count || (p1.count==p2.count && p1.time<p2.time)) return true;
    return false;
}

int main()
{
    int n,g,s,c,m;
    int temp;
    PP pp[150];
    PP my;

    int i,j;
    while(scanf("%d%d%d%d%d",&n,&g,&s,&c,&m) && (n||g||s||c||m))
    {
        int num;
        bool flag = false;
        for(i=0; i<n; i++)
        {
            scanf("%d",&pp[i].count);
            cin>>pp[i].time;
        }
        my = pp[m-1];
        sort(pp,pp+n,cmp);

        for(i=0; i<n; i++)
        {
            if(pp[i].count == my.count  && my.time == pp[i].time) break;
        }
        num = i+1;
        if(num<=g) cout<<"Accepted today? I've got a golden medal :)"<<endl;
        else if(num<=g+s) cout<<"Accepted today? I've got a silver medal :)"<<endl;
        else if(num<=g+s+c) cout<<"Accepted today? I've got a copper medal :)"<<endl;
        else cout<<"Accepted today? I've got an honor mentioned :)"<<endl;
    }
    return 0;
}

  1. for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
    dp = dp [j-1] + 1;
    if(s1.charAt(i-1) == s3.charAt(i+j-1))
    dp = dp[i-1] + 1;
    if(s2.charAt(j-1) == s3.charAt(i+j-1))
    dp = Math.max(dp [j - 1] + 1, dp );
    }
    }
    这里的代码似乎有点问题? dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false

  2. 这道题目虽然简单,但是小编做的很到位,应该会给很多人启发吧!对于面试当中不给开辟额外空间的问题不是绝对的,实际上至少是允许少数变量存在的。之前遇到相似的问题也是恍然大悟,今天看到小编这篇文章相见恨晚。