首先(我似乎只会这样写 )看一下题叭:
P4667 [BalticOI 2011 Day1]Switch the Lamp On
首先这道题要用广搜做,不过这里要用点而不是格,所以注意要把格转化为点。其次,因为我们遍历的点而不是格,所以有6个方向要进行遍历,可以遍历上下左右,另外两个方向依据情况而定。我们可以定义一个数组,既可以当做标记,也可以当做cnt来用。
代码如下:
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <map>
#define inf 0x7ffffff
#define ll long long
//#include <windows.h>
//#include <bits/stdc++.h>
using namespace std;
/*
输入:
输出:
*/
int n,m;//n*m
char map1[601][601];
struct node {
int x,y,step;
} wer;
int book[601][601];
deque <node> q;
1:左上 ,2:左下,3:右上,4:右下
int nxtx[10]= {
0,-1,1