洛谷 2038 无线网络发射器选址——枚举

题目:https://www.luogu.org/problemnew/show/P2038

暴枚一下坐标就行了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=25;
int n,x[N],y[N],w[N],ans,prn,d,x1,y1,x2,y2,sum;
int main()
{
  scanf("%d%d",&d,&n);
  for(int i=1;i<=n;i++)
      scanf("%d%d%d",&x[i],&y[i],&w[i]);
  for(int i=0;i<=128;i++)
    for(int j=0;j<=128;j++)
      {
    x1=i-d; x2=i+d; y1=j-d; y2=j+d;
    sum=0;
    for(int k=1;k<=n;k++)
        if(x[k]>=x1&&x[k]<=x2&&y[k]>=y1&&y[k]<=y2) sum+=w[k];
    if(sum==ans) prn++;
    else if(sum>ans) ans=sum,prn=1;
      }
  printf("%d %d\n",prn,ans);
  return 0;
}

猜你喜欢

转载自www.cnblogs.com/Narh/p/9641682.html