GPMB - Giải phóng mặt bằng
Tác giả: skyvn97
Ngôn ngữ: C++
#include<cstdio>
struct point {
int x,y;
point(){}
point(const int &_x,const int &_y) {
x=_x;y=_y;
}
};
point a[1515];
int c[111][111];
int f[111][111];
int n;
void init(void) {
scanf("%d",&n);
int i,x,y,s;
for (x=0;x<=100;x=x+1)
for (y=0;y<=100;y=y+1) c[x][y]=0;
for (i=1;i<=n;i=i+1) {
scanf("%d",&x);
scanf("%d",&y);
scanf("%d",&s);
c[x+50][y+50]+=s*s+5;
a[i]=point(x+50,y+50);
}
}
int gcd(const int &a,const int &b) {
if (a==0) return (b);
if (b==0) return (a);
if (a%b==0) return (b);
if (b%a==0) return (a);
if (a>b) return (gcd(a%b,b));
if (b>a) return (gcd(a,b%a));
}
void count(void) {
int i,j;
for (i=0;i<=100;i=i+1)
for (j=0;j<=100;j=j+1)
f[i][j]=gcd(i,j);
}
bool inside(const int &x,const int &y) {
if (x<0) return (false);
if (y<0) return (false);
if (x>100) return (false);
if (y>100) return (false);
return (true);
}
int max(const int &x,const int &y) {
if (x>y) return (x); else return (y);
}
void process(void) {
int res=0;
int i,j,k,dx,dy,t,s;
for (i=0;i<=100;i=i+1)
for (j=0;j<=100;j=j+1)
if (f[i][j]==1)
for (k=1;k<=n;k=k+1) {
s=c[a[k].x][a[k].y];
dx=i;
dy=j;
for (t=1;t<=500;t=t+1) {
if (!inside(a[k].x+t*dx,a[k].y+t*dy)) break;
s+=c[a[k].x+t*dx][a[k].y+t*dy];
}
for (t=1;t<=500;t=t+1) {
if (!inside(a[k].x-t*dx,a[k].y-t*dy)) break;
s+=c[a[k].x-t*dx][a[k].y-t*dy];
}
res=max(res,s);
s=c[a[k].x][a[k].y];
dx=-i;
dy=j;
for (t=1;t<=500;t=t+1) {
if (!inside(a[k].x+t*dx,a[k].y+t*dy)) break;
s+=c[a[k].x+t*dx][a[k].y+t*dy];
}
for (t=1;t<=500;t=t+1) {
if (!inside(a[k].x-t*dx,a[k].y-t*dy)) break;
s+=c[a[k].x-t*dx][a[k].y-t*dy];
}
res=max(res,s);
}
printf("%d",res);
}
int main(void) {
init();
count();
process();
}