72分求助,#2#4WA
  • 板块P3392 涂国旗
  • 楼主zhibuba
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/5/28 12:32
  • 上次更新2023/11/7 01:34:55
查看原帖
72分求助,#2#4WA
319478
zhibuba楼主2020/5/28 12:32
#include <stdio.h>

struct row{
	int W, B, R;
} A[50];

enum {w, b, r
};

int ans = 2500;

int sum(int start, int end, int color)
{
	int s = 0;
	for (int i = start; i <= end; i++)
	{
		switch(color)
		{
			case w: s += A[i].R + A[i].B; break;
			case b:	s += A[i].R + A[i].W; break;
			case r: s += A[i].B + A[i].W; break;		
		}
	}
	return s;
}

int main(void)
{
	int N, M;
	scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++)
	{
		scanf("%*[\n\r]");
		for (int j = 0; j < M; j++)
		{
			char c = getchar();
			switch (c)
			{
				case 'W': A[i].W++; break;
				case 'B': A[i].B++; break;
				case 'R': A[i].R++; break;
			}
		}
	}
	
	int tmp = 0;
	for (int i = 0; i < M - 2; i++)
	{
		for (int j = i + 1; j < M - 1; j++)
		{
			tmp = sum(0, i, w) + sum(i + 1, j, b) + sum(j + 1, M, r);
			if (tmp < ans)
				ans = tmp;
		}
	}
	printf("%d", ans);
	return 0;
}
2020/5/28 12:32
加载中...