L - Very Simple Problem

During a preparation of programming contest, its jury is usually faced with many difficult tasks. One of them is to select a problem simple enough to most, if not all, contestants to solve.
The difficulty here lies in diverse meanings of the term “simple” amongst the jury members. So, the jury uses the following procedure to reach a consensus: each member weights each proposed problem with a positive integer “complexity rating” (not necessarily different for different problems). The jury member calls “simplest” those problems that he gave the minimum complexity rating, and “hardest” those problems that he gave the maximum complexity rating.
The ratings received from all jury members are then compared, and a problem is declared as “very simple”, if it was called as “simplest” by more than a half of the jury, and was called as “hardest” by nobody.

Input
The first line of input file contains integers N and P, the number of jury members and the number of problems. The following N lines contain P integers in range from 0 to 1000 each - the complexity ranks. 1 <= N, P <= 100
Output
Output must contain an ordered list of problems called as “very simple”, separated by spaces. If there are no such problems, output must contain a single integer 0 (zero).
Sample Input
4 4
1 1 1 2
5 900 21 40
10 10 9 10
3 4 3 5
Sample Output
3

题意:n个裁判,给p个问题评分,找所有最简单的问题。
最简单的问题是:如果它被超过一半的裁判称为“最简单的”,而没有人称它为“最难的”。
举个例子 样例第二行是第一个裁判对p个问题评判,p个分数中最低分数的那个题是最简单的题。
第i个裁判 它认为的最简单的题是(从1开始)
1 1、2、3
2 1
3 3
4 1、3
所以样例得出结果,最简单的题只有一个,第三题。第一题为什么没有被算作最简单的,因为它被第3给裁判认为是最难的。
最简单的问题是:如果它被超过一半的裁判称为“最简单的”,而没有人称它为“最难的”。

#include<iostream>
#include<cstring>
using namespace std;
/*
看成一行是一个描述了
and a problem is declared as "very simple",
if it was called as "simplest" by more than a half of the jury,
and was called as "hardest" by nobody.
对于一个问题
第i行是第i个裁判对0~p个问题给的分数,给的最低分是simplest,也就是我们要求的
给的最高分说明这个问题是p个问题中最难的,不能再算在内了,注意条件(was called as "hardest" by nobody.)
如果超过一半的裁判认为那个问题是p个问题中simplest的问题,那么它纳入输出的序列中。
一个都没有的话,输出零
*/
int main()
{
    int n,p;
    while(cin>>n>>p)
    {
        int a[101];
        memset(a,0,sizeof(a));//忘记初始化WA了一次
        for(int i=0;i<n;i++)
        {
            int _max=-1,_min=1001;
            //先找出最难的难度,和最简单的难度
            int x[p];
            for(int j=0;j<p;j++)
            {
                cin>>x[j];
                if(x[j]>_max)
                    _max = x[j];
                if(x[j]<_min)
                    _min = x[j];

            }

            for(int j=0;j<p;j++)
            {
                if(x[j] == _max&&a[j]!=-1)//如果它是最难的话
                    a[j] = -1;//第j个问题已经不可能进入输出序列了
                if(x[j] == _min&&a[j]!=-1)
                    a[j] ++;
            }
        }
        int first = 0;
        for(int i=0;i<p;i++)
        {
            if(a[i] == -1)
                continue;
            if(a[i]>n/2)
            {
                if(first)
                    cout<<" ";
                cout<<i+1;
                first = 1;
            }
        }
        if(first == 0)
            cout<<"0";
        cout<<endl;
    }

}

猜你喜欢

转载自blog.csdn.net/qq_36734025/article/details/81181714
今日推荐