【FOJ】Problem 1350 Very Simple Problem

Problem 1350 Very Simple Problem.

题意

  • 非常简单 = 超过一半的法官觉得这个问题最简单 + 没有法官觉得这个问题最难
  • 输入:多组输入
    法官数N,问题数P(1 <= N, P <= 100)
    N行每行P个数据,表示问题的复杂度 r(0-1000)
  • 输出:
    非常简单的问题列表,用空格隔开
    如果没有问题符合条件,则输出0

思路

  • 对每一个法官,分别记录下他的最低复杂度和最高复杂度
  • 改变count[]的值:
    count[i] = -1 表示这个问题有法官认为最难
    count[i] > 0 表示这个问题被法官们判定为最简单问题的次数
  • 遍历数组,当 count[i] > N/2 时,输出i

笔记

  • FOJ默认多组输入
  • 复杂度数据可重复,即每个法官可以判定多个最简单问题和多个最复杂问题

代码

#include<cstdio>
#include<string.h>
using namespace std;

int count[100];
int rate[100][100];

int main(){
	int n, p;
	int easy, hard;
	while(scanf("%d%d", &n, &p)!=EOF){
		memset(count, 0, sizeof(count));
		for(int i=0; i<n; i++){
			easy = 1000;
			hard = 0;
			for(int j=0; j<p; j++){
				scanf("%d", &rate[i][j]);
				if(rate[i][j]>hard)
					hard = rate[i][j];
				if(rate[i][j]<easy)
					easy = rate[i][j];
			}
			for(int j=0; j<p; j++){
				if(rate[i][j]==hard)
					count[j] = -1;
				if(rate[i][j]==easy && count[j]!=-1)
					count[j]++;
			}
		}
		int ans[100], len=0;
		for(int i=0; i<p; i++)
			if(count[i]>=n/2.0)
				ans[len++] = i+1;
		if(len==0)
			printf("0");
		for(int i=0; i<len; i++){
			printf("%d", ans[i]);
			if(i<len-1)
				printf(" ");
		}
		printf("\n");
	}
	return 0;
}
发布了29 篇原创文章 · 获赞 0 · 访问量 343

猜你喜欢

转载自blog.csdn.net/qq_44531167/article/details/105371264