样例输入:
1
2
4 4 10
6 6 20
我的wrong answer代码,球球大佬帮我看看!
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
int d, n, x[21], y[21], w[21];
cin >> d >> n;
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i] >> w[i];
int large = 0,count=0;
for (int i = 0; i <= 1025; i++) {
for (int j = 0; j <= 1025; j++) {
int maxx=0;
for (int k = 0; k < n; k++) {
if (abs(i - x[k]) <= d && abs(j - y[k]) <= d) {
maxx += w[k];
}
}
if (maxx > large) {
count = 1;
large = maxx;
}
else if (maxx == large) {
count++;
}
}
}
cout << count << " " << large;
return 0;
}
AC代码
#include<bits/stdc++.h>
using namespace std;
#define N 1030
struct Garbage
{
int x, y, i;//(x,y)处有垃圾数量i
}g[25];//g[i]:第i个垃圾路口
int main()
{
int d, n, mxSum = 0, ct;//mxSum:最大销毁垃圾数目 ct:可以销毁mxSum数量垃圾的炸弹安放位置数
cin >> d >> n;
for(int i = 1; i <= n; ++i)
cin >> g[i].x >> g[i].y >> g[i].i;
for(int i = 0; i <= 1024; ++i)
for(int j = 0; j <= 1024; ++j)
{//在(i,j)位置放炸弹
int sum = 0;//在(i,j)位置安放炸弹销毁的垃圾总和
for(int k = 1; k <= n; ++k)//看垃圾路口g[k]是否在(i,j)炸弹的范围之内
if(abs(i-g[k].x) <= d && abs(j-g[k].y) <= d)
sum += g[k].i;
if(sum > mxSum)
{
mxSum = sum;//最大销毁垃圾数量
ct = 1;//能销毁mxSum的炸弹位置变为1
}
else if(sum == mxSum)
ct++;//能销毁mxSum的炸弹位置增加1
}
cout << ct << ' ' << mxSum;
return 0;
}