求助
查看原帖
求助
71922
影子鱼llt楼主2020/7/12 12:15

90pts

#include<stdio.h>
#include<algorithm>
using namespace std;
int mmap[5110][5110];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int maxx = 0,maxy = 0;
    for(int i = 0;i < n;i++)
    {
        int x,y,val;
        scanf("%d%d%d",&x,&y,&val);
        mmap[x + 1][y + 1] += val;
        maxx = max(maxx,x + 1),maxy = max(maxy,y + 1);
    }
    for(int x = 1;x <= maxx;x++)
        for(int y = 1;y <= maxy;y++)
            mmap[x][y] += mmap[x - 1][y] + mmap[x][y - 1] - mmap[x - 1][y - 1];
    int ans = -1;
    for(int x = m;x <= maxx;x++)
        for(int y = m;y <= maxy;y++)
            ans = max(ans,mmap[x - m][y - m] - mmap[x][y - m] - mmap[x - m][y] + mmap[x][y]);
    printf("%d",ans);
    return 0;
}

100pts

#include<stdio.h>
#include<string.h>

#include<algorithm>
using namespace std;

int tot[5050][5050];

void read(int &n)
{
    char c='+';int x=0;bool flag=0;
    while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}
    while(c>='0'&&c<='9')
    {x=x*10+c-48;c=getchar();}
    flag==1?n=-x:n=x;
}

int main()
{
	int n,r;
	read(n);read(r);
	for(int i = 0;i < n;i++)
	{
		int x, y, val;
		read(x);read(y);read(val);
		tot[x + 1][y + 1] = val;
	}
	for(int i = 1;i < 5005;i++)
	{
		for(int j = 1;j < 5005;j++)
		{
			tot[i][j] = tot[i][j] + tot[i - 1][j] + tot[i][j - 1] - tot[i - 1][j - 1];
		}
	}
	int ans = -1;
	for (int i = 0; i <= 5001 - r; i++)
		for (int j = 0; j <= 5001 - r; j++)
			ans = max(ans, tot[i + r][j + r] - tot[i + r][j] - tot[i][j + r] + tot[i][j]);
	printf("%d",ans);
	return 0;
}

Why?

2020/7/12 12:15
加载中...