英文题:Very Simple Problem

Title Description
     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
 

题目代码转载:

 注明转载代码地址链接:https://www.nowcoder.com/questionTerminal/69193ff3dd8d4dcf929c109372463d0b

代码如下:

#include<iostream>
#include<stdio.h>
using namespace std;
int a[150][150];
int c[150],d[150];
int ans[150],tn;
/*
题目描述:
    n,m,表示n个人,m个题目。
    每一行就是每一个人对于每一个题目的评价。
    题目:
      某一个题目的评价,在别人所有的题目评价中,
      1、不是最高的评价,2、是最低的评价。
    求这样人的数目,要求超过一半。则该问题被认为最简单的题目。输出题目标号。
    要求:
      1、这样的人数超过半数人
      2、这样的题目不能再某一个人中被认为最难
*/
int main()
{
    int n,p;
    int tp,tmax;
    while( scanf("%d%d",&n,&p)!=EOF)
    {
        for(int i=0; i<n; i++)
        {
            tp = 1001;
            tmax = 0;
            for(int j=0; j<p; j++)
            {
                scanf("%d",&a[i][j]);
                if( a[i][j] < tp )
                    tp = a[i][j];
                if( a[i][j] > tmax )
                    tmax = a[i][j];
            }
            c[ i ] = tp;
            d[ i ] = tmax;
        }
        tn=0;
        for(int i=0; i<p; i++)
        {
            tp = 0;
            for(int j=0; j<n; j++)
            {
                if( a[ j ][ i ] == c[ j ] )
                    tp++;
                if( a[ j ][ i ] == d[ j ] )
                {
                    tp=0;
                    break;
                }
            }
            if( tp > n/2 )
                ans[ tn++ ] = i+1;
        }
        if( tn == 0 )
            printf("0");
        for(int i=0; i<tn; i++)
        {
            if( i )
                printf(" ");
            printf("%d",ans[i]);
        }
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zjwsa/article/details/81173981
今日推荐