标签:blog io for 2014 log amp size as file
a[i][j]记录以i,j为右下角的矩形内所有价值和,然后枚举每一个点位置的正方形所能取得的价值
#include "stdio.h" #include "string.h" int a[5110][5110]; int Max(int a,int b) { if (a<b) return b;else return a; } int main() { int n,r,Mx,My,ans,i,j,x,y,z; while (scanf("%d%d",&n,&r)!=EOF) { memset(a,0,sizeof(a)); Mx=My=5002; while (n--) { scanf("%d%d%d",&x,&y,&z); x++; y++; a[x][y]+=z; } for (i=1;i<=Mx;i++) for (j=1;j<=My;j++) a[i][j]+=a[i][j-1]+a[i-1][j]-a[i-1][j-1]; ans=0; for (i=0;i<Mx-r;i++) for (j=0;j<My-r;j++) ans=Max(ans,a[i+r][j+r]-a[i+r][j]-a[i][j+r]+a[i][j]); printf("%d\n",ans); } return 0; }
标签:blog io for 2014 log amp size as file
原文地址:http://blog.csdn.net/u011932355/article/details/40350867