题目大意
http://cxsjsx.openjudge.cn/2015finalpractice/43/
讲真这题的大意我真的真的概括不来,各位看官老爷还是直接在原题目上看吧,顺便给出一个提交的链接。
题解
作为一道擅长屎题 向往屎题 热爱屎题的选手,不得不说,这道题确是一道搜索好(shi)题,所考察的搜索剪枝相关的知识点也是非常的全面。没有比较就没有差距,首先我放上一份无脑而又暴力的代码上来。
暴力代码 (哇这代码真他妈丑)
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
struct Point { //存储稻田中被糟蹋的坐标
int x,y;
Point() {}
Point(int _x,int _y):x(_x),y(_y) {}
bool operator < (const Point &b) const {
if(x!=b.x) return x<b.x;
return y<b.y;
}
}p[1005];
const int maxn=55;
int n,m,k;
int Map[maxn][maxn];
int sum;
inline bool inrange(const int &x,const int &y) {
if(x<1 || y<1 || x>n || y>m) return false;
return true;
}
int lit;
bool dfs(int dep) {
if(dep==lit) {
if(!sum) return true;
else return false;
}
register int i,j,x,y,u,v;
for(i=1;i<=k;++i) if(Map[p[i].x][p[i].y])
for(j=i+1;j<=k;++j) if(i!=j && Map[p[j].x][p[j].y]) { //枚举路径上的两个相邻的点
x=p[i].x, y=p[i].y;
u=p[j].x, v=p[j].y;
register int p1,p2,dx=x-u,dy=y-v;
int cnt=0, flag=true;
for(p1=u,p2=v;flag && inrange(p1,p2);p1+=dx,p2+=dy)