hdu4462--曼哈顿距离

题目大意:有N*N个点的田野,然后有k个点是用来放稻草人的,每个稻草人对周围满足曼哈顿距离的庄稼有保护作用

问最小的稻草人的个数能够保护所有庄稼,如果不能保护则输出-1

注意的地方:

1.放稻草人的点不需要计算,因为不是庄稼

2.可能存在0的解,也就是k=N*N时

思路:二进制枚举所有情况,找到最小解

代码如下:

#include
#include
#include
#include
using namespace std;
const int maxs = 51;
int n,k;
bool vis[maxs][maxs];
struct Point
{
   int x,y;
   int dis;
}point[11];

bool judge(Point p[],int t,Point goal)
{
    for(int i=0;i

 

转载于:https://www.cnblogs.com/wt20/p/5785362.html

你可能感兴趣的:(hdu4462--曼哈顿距离)