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

输入

The input include multiple test cases.

The first line of each test case 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

输出

For each test case, output one line and contain an ascending 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).

样例输入
4 4
1 1 1 2
5 900 21 40
10 10 9 10
3 4 3 5
样例输出
3




首先找出每位评委给分最低的题目编号,然后对全部题目进行遍历,统计题目的最低评分个数是否超过一半,并且没有最高得分。我这里是用-1来表示最低评分的,-2表示最高得分,最后统计每道题目中-1的个数,并且没有-2,进行比较即可。
注意此题是多组数据


#include <stdio.h>

int main()
{
	int n,p;
	int i,j;
	int a[100][100];
	int flag[100];
	int upset;
	int min;
	int max;
	int k;
	int sum;
	int answer;
	
	while(scanf("%d %d",&n,&p)!=EOF)
	{

	

	answer=0;

	for(i=0;i<n;i++)
		for (j=0;j<p;j++)
		{
			scanf("%d",&a[i][j]);
		}


	for(i=0;i<n;i++)
	{
		min=a[i][0];
		max=a[i][0];
		for(j=0;j<p;j++)
		{
			
			if(a[i][j]<min)
			{
				min=a[i][j];
			}
			if(a[i][j]>max)
			{
				max=a[i][j];
			}

		}

		for(k=0;k<p;k++)
		{
			if(a[i][k]==max)
			{
				a[i][k]=-2;
			}
			if(a[i][k]==min)
			{
				a[i][k]=-1;
			}

		}
	}

	k=0;

	for(i=0;i<p;i++)
	{
		sum=0;
		upset=0;

		for(j=0;j<n;j++)
		{
			if(a[j][i]==-1)
			{
				sum++;
			}
			if(a[j][i]==-2)
			{
				upset=1;

			}
			

		}

		if(sum>n/2&&upset==0)
		{
			answer++;
			flag[k++]=i+1;
		}
	}

	if(answer==0)
	{
		printf("%d\n",answer);
	}
	else
	{
		for(i=0;i<k-1;i++)
			printf("%d ",flag[i]);

		printf("%d\n",flag[k-1]);
	}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值