璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:usaco21jan_spaced_out_s
problems
名称Spaced Out S
题目编号USACO21JAN_S3
题目链接luogu.com.cn/…
来源USACO
算法分类思维, 贪心
难易程度容易

Spaced Out S

想法

观察要求:2*2的范围内,必须有2个C。所以对于某个特定的区域内,只有2种情况:1. 列交替;2. 行交替。所以分别去统计对于某一列,交替方案的最大值求和;对于某一行,交替方案点最大值求和。取最优的方案。

代码实现

#include<cstdio>
#include<algorithm>
using namespace std;
 
const int N = 1010;
int maps[N][N];
int n;
 
int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			scanf("%d", &maps[i][j]);
 
	int ans1 = 0;
	for(int i=1; i<=n; i++)
	{
		int res[2]={0, 0};
		for(int j=1; j<=n; j++)
			res[j&1] += maps[i][j];
		ans1 += max(res[0], res[1]);
	}
 
	int ans2 = 0;
	for(int i=1; i<=n; i++)
	{
		int res[2]={0, 0};
		for(int j=1; j<=n; j++)
			res[j&1] += maps[j][i];
		ans2 += max(res[0], res[1]);
	}
 
	printf("%d", max(ans1, ans2));
	return 0;
} 
/app/www/public/data/pages/icpc/problems/usaco21jan_spaced_out_s.txt · 最后更改: 2023/03/25 09:33 由 温婕莺