首页 > ACM题库 > HDU-杭电 > hdu 2309 ICPC Score Totalizer Software[解题报告]C++
2014
01-05

hdu 2309 ICPC Score Totalizer Software[解题报告]C++

ICPC Score Totalizer Software

问题描述 :

The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.
One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance.

Basically, scores given to a contestant’s performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer.

You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.

输入:

The input consists of a number of datasets, each corresponding to a contestant’s performance. There are no more than 20 datasets in the input.

A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges’ names are kept secret.

The end of the input is indicated by a line with a single zero in it.

输出:

The input consists of a number of datasets, each corresponding to a contestant’s performance. There are no more than 20 datasets in the input.

A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges’ names are kept secret.

The end of the input is indicated by a line with a single zero in it.

样例输入:

3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0

样例输出:

342
7
300
326

题目比较简单。

思路:读入一组分数,去除最高和最低分,再求余下分数的平均分即可。

实现:用STL的vector很方便,接着用到sort算法,自己也不用写快排了。

收获:发现将变量的声明放在循环体while内,时间会不所增加;而放在外面效率则高些。

代码一:

/*Memory: 716K  Time: 0MS 
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    vector<int> scores;
    int score;
    double sumScore;
    int aveScore;
    int n;
    while(cin >> n, n !=0) {
        scores.clear();

        for(int i = 0; i < n; i++) {
            cin >> score;
            scores.push_back(score);
        }

        sort(scores.begin(), scores.end());

        scores.erase(scores.end() - 1, scores.end());
        scores.erase(scores.begin(), scores.begin() + 1);

        sumScore = 0.0;
        for(vector<int>::iterator iter = scores.begin();
            iter != scores.end(); iter++) {
            sumScore += *iter;
        }
        aveScore = (int)(sumScore / scores.size());

        cout << aveScore << endl;
    }

    return 0;
}

代码二:

/*Memory: 716K  Time: 32MS 
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    //vector<int> scores;
    //int score;
    //double sumScore;
    //int aveScore;
    int n;
    while(cin >> n, n !=0) {
        //scores.clear();
        vector<int> scores;
        int score;

        for(int i = 0; i < n; i++) {
            cin >> score;
            scores.push_back(score);
        }

        sort(scores.begin(), scores.end());

        scores.erase(scores.end() - 1, scores.end());
        scores.erase(scores.begin(), scores.begin() + 1);

        //sumScore = 0.0;
        double sumScore = 0.0;
        for(vector<int>::iterator iter = scores.begin();
            iter != scores.end(); iter++) {
            sumScore += *iter;
        }
        int aveScore = (int)(sumScore / scores.size());

        cout << aveScore << endl;
    }

    return 0;
}

解题转自:http://blog.csdn.net/lihao21/article/details/6155927


  1. 漂亮。佩服。
    P.S. unsigned 应该去掉。换行符是n 不是/n
    还可以稍微优化一下,
    int main() {
    int m,n,ai,aj,bi,bj,ak,bk;
    while (scanf("%d%d",&m,&n)!=EOF) {
    ai = sqrt(m-1);
    bi = sqrt(n-1);
    aj = (m-ai*ai-1)>>1;
    bj = (n-bi*bi-1)>>1;
    ak = ((ai+1)*(ai+1)-m)>>1;
    bk = ((bi+1)*(bi+1)-n)>>1;
    printf("%dn",abs(ai-bi)+abs(aj-bj)+abs(ak-bk));
    }
    }

  2. #include <stdio.h>
    int main()
    {
    int n,p,t[100]={1};
    for(int i=1;i<100;i++)
    t =i;
    while(scanf("%d",&n)&&n!=0){
    if(n==1)
    printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
    else {
    if(n%4) p=n/4+1;
    else p=n/4;
    int q=4*p;
    printf("Printing order for %d pages:n",n);
    for(int i=0;i<p;i++){
    printf("Sheet %d, front: ",i+1);
    if(q>n) {printf("Blank, %dn",t[2*i+1]);}
    else {printf("%d, %dn",q,t[2*i+1]);}
    q–;//打印表前
    printf("Sheet %d, back : ",i+1);
    if(q>n) {printf("%d, Blankn",t[2*i+2]);}
    else {printf("%d, %dn",t[2*i+2],q);}
    q–;//打印表后
    }
    }
    }
    return 0;
    }

  3. /*
    * =====================================================================================
    *
    * Filename: 1366.cc
    *
    * Description:
    *
    * Version: 1.0
    * Created: 2014年01月06日 14时52分14秒
    * Revision: none
    * Compiler: gcc
    *
    * Author: Wenxian Ni (Hello World~), [email protected]
    * Organization: AMS/ICT
    *
    * =====================================================================================
    */

    #include
    #include

    using namespace std;

    int main()
    {
    stack st;
    int n,i,j;
    int test;
    int a[100001];
    int b[100001];
    while(cin>>n)
    {
    for(i=1;i>a[i];
    for(i=1;i>b[i];
    //st.clear();
    while(!st.empty())
    st.pop();
    i = 1;
    j = 1;

    while(in)
    break;
    }
    while(!st.empty()&&st.top()==b[j])
    {
    st.pop();
    j++;
    }
    }
    if(st.empty())
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
    }