problem link:
Discuss: in this problem you have calculate all the position value. which is possible near to bomb.for that you can determine the maximum and minimum range from given output by adding and subtracting with the point.then add size to every grid. and obviously largest grid value will give the largest rat.
try your self before see the code
#include<bits/stdc++.h>
using namespace std;
int ara[1025][1025];
int main()
{
int n,i,j,t,x,y,fx,fy,d,p,q,r,s,siz;
cin >>t;
while(t--)
{
memset(ara,false,sizeof(ara));
int mx=-1;
cin >>d>>n;
while(n--)
{
cin >>x>>y>>siz;
p=max(0,x-d);
q=min(x+d,1024);
r=max(0,y-d);
s=min(y+d,1024);
for(i=p;i<=q;i++)
{
for(j=r;j<=s;j++)
{
ara[i][j]+=siz;
}
}
}
for(i=0;i<1025;i++)
{
for(j=0;j<1025;j++)
{
if(mx<ara[i][j])
{
mx=ara[i][j];
fx=i;
fy=j;
}
}
}
cout <<fx<<' '<<fy<<' '<<mx<<endl;
}
return 0;
Discuss: in this problem you have calculate all the position value. which is possible near to bomb.for that you can determine the maximum and minimum range from given output by adding and subtracting with the point.then add size to every grid. and obviously largest grid value will give the largest rat.
try your self before see the code
#include<bits/stdc++.h>
using namespace std;
int ara[1025][1025];
int main()
{
int n,i,j,t,x,y,fx,fy,d,p,q,r,s,siz;
cin >>t;
while(t--)
{
memset(ara,false,sizeof(ara));
int mx=-1;
cin >>d>>n;
while(n--)
{
cin >>x>>y>>siz;
p=max(0,x-d);
q=min(x+d,1024);
r=max(0,y-d);
s=min(y+d,1024);
for(i=p;i<=q;i++)
{
for(j=r;j<=s;j++)
{
ara[i][j]+=siz;
}
}
}
for(i=0;i<1025;i++)
{
for(j=0;j<1025;j++)
{
if(mx<ara[i][j])
{
mx=ara[i][j];
fx=i;
fy=j;
}
}
}
cout <<fx<<' '<<fy<<' '<<mx<<endl;
}
return 0;
}
No comments:
Post a Comment